Geen omschrijving

Sample_32_Chart.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. include_once 'Sample_Header.php';
  3. use PhpOffice\PhpWord\Shared\Converter;
  4. // New Word document
  5. echo date('H:i:s'), ' Create new PhpWord object', EOL;
  6. $phpWord = new \PhpOffice\PhpWord\PhpWord();
  7. $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
  8. $phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
  9. // 2D charts
  10. $section = $phpWord->addSection();
  11. $section->addTitle(htmlspecialchars('2D charts'), 1);
  12. $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
  13. $chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
  14. $twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar');
  15. $threeSeries = array('bar', 'line');
  16. $categories = array('A', 'B', 'C', 'D', 'E');
  17. $series1 = array(1, 3, 2, 5, 4);
  18. $series2 = array(3, 1, 7, 2, 6);
  19. $series3 = array(8, 3, 2, 5, 4);
  20. foreach ($chartTypes as $chartType) {
  21. $section->addTitle(ucfirst($chartType), 2);
  22. $chart = $section->addChart($chartType, $categories, $series1);
  23. $chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
  24. if (in_array($chartType, $twoSeries)) {
  25. $chart->addSeries($categories, $series2);
  26. }
  27. if (in_array($chartType, $threeSeries)) {
  28. $chart->addSeries($categories, $series3);
  29. }
  30. $section->addTextBreak();
  31. }
  32. // 3D charts
  33. $section = $phpWord->addSection(array('breakType' => 'continuous'));
  34. $section->addTitle(htmlspecialchars('3D charts'), 1);
  35. $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
  36. $chartTypes = array('pie', 'bar', 'column', 'line', 'area');
  37. $multiSeries = array('bar', 'column', 'line', 'area');
  38. $style = array('width' => Converter::cmToEmu(5), 'height' => Converter::cmToEmu(4), '3d' => true);
  39. foreach ($chartTypes as $chartType) {
  40. $section->addTitle(ucfirst($chartType), 2);
  41. $chart = $section->addChart($chartType, $categories, $series1, $style);
  42. if (in_array($chartType, $multiSeries)) {
  43. $chart->addSeries($categories, $series2);
  44. $chart->addSeries($categories, $series3);
  45. }
  46. $section->addTextBreak();
  47. }
  48. // Save file
  49. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  50. if (!CLI) {
  51. include_once 'Sample_Footer.php';
  52. }