Sample_05_Chart_Line.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. include_once 'Sample_Header.php';
  3. use PhpOffice\PhpPresentation\PhpPresentation;
  4. use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
  5. use PhpOffice\PhpPresentation\Shape\Chart\Series;
  6. use PhpOffice\PhpPresentation\Style\Border;
  7. use PhpOffice\PhpPresentation\Style\Color;
  8. use PhpOffice\PhpPresentation\Style\Fill;
  9. use PhpOffice\PhpPresentation\Style\Shadow;
  10. // Create new PHPPresentation object
  11. echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
  12. $objPHPPresentation = new PhpPresentation();
  13. // Set properties
  14. echo date('H:i:s') . ' Set properties' . EOL;
  15. $objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')->setLastModifiedBy('PHPPresentation Team')->setTitle('Sample 07 Title')->setSubject('Sample 07 Subject')->setDescription('Sample 07 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
  16. // Remove first slide
  17. echo date('H:i:s') . ' Remove first slide' . EOL;
  18. $objPHPPresentation->removeSlideByIndex(0);
  19. // Set Style
  20. $oFill = new Fill();
  21. $oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
  22. $oShadow = new Shadow();
  23. $oShadow->setVisible(true)->setDirection(45)->setDistance(10);
  24. // Generate sample data for chart
  25. echo date('H:i:s') . ' Generate sample data for chart' . EOL;
  26. $seriesData = array(
  27. 'Monday' => 12,
  28. 'Tuesday' => 15,
  29. 'Wednesday' => 13,
  30. 'Thursday' => 17,
  31. 'Friday' => 14,
  32. 'Saturday' => 9,
  33. 'Sunday' => 7
  34. );
  35. // Create templated slide
  36. echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
  37. $currentSlide = createTemplatedSlide($objPHPPresentation);
  38. // Create a line chart (that should be inserted in a shape)
  39. echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
  40. $lineChart = new Line();
  41. $series = new Series('Downloads', $seriesData);
  42. $series->setShowSeriesName(true);
  43. $series->setShowValue(true);
  44. $lineChart->addSeries($series);
  45. // Create a shape (chart)
  46. echo date('H:i:s') . ' Create a shape (chart)' . EOL;
  47. $shape = $currentSlide->createChartShape();
  48. $shape->setName('PHPPresentation Daily Downloads')->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  49. $shape->setShadow($oShadow);
  50. $shape->setFill($oFill);
  51. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  52. $shape->getTitle()->setText('PHPPresentation Daily Downloads');
  53. $shape->getTitle()->getFont()->setItalic(true);
  54. $shape->getPlotArea()->setType($lineChart);
  55. $shape->getView3D()->setRotationX(30);
  56. $shape->getView3D()->setPerspective(30);
  57. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  58. $shape->getLegend()->getFont()->setItalic(true);
  59. // Create templated slide
  60. echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
  61. $currentSlide = createTemplatedSlide($objPHPPresentation);
  62. // Create a line chart (that should be inserted in a shape)
  63. $oOutline = new \PhpOffice\PhpPresentation\Style\Outline();
  64. $oOutline->getFill()->setFillType(Fill::FILL_SOLID);
  65. $oOutline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW));
  66. $oOutline->setWidth(2);
  67. echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
  68. $lineChart1 = clone $lineChart;
  69. $series1 = $lineChart1->getSeries();
  70. $series1[0]->setOutline($oOutline);
  71. $series1[0]->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_DIAMOND);
  72. $series1[0]->getMarker()->setSize(7);
  73. $lineChart1->setSeries($series1);
  74. // Create a shape (chart)
  75. echo date('H:i:s') . ' Create a shape (chart1)' . EOL;
  76. echo date('H:i:s') . ' Differences with previous : Values on right axis and Legend hidden' . EOL;
  77. $shape1 = clone $shape;
  78. $shape1->getLegend()->setVisible(false);
  79. $shape1->setName('PHPPresentation Weekly Downloads');
  80. $shape1->getTitle()->setText('PHPPresentation Weekly Downloads');
  81. $shape1->getPlotArea()->setType($lineChart1);
  82. $shape1->getPlotArea()->getAxisY()->setFormatCode('#,##0');
  83. $currentSlide->addShape($shape1);
  84. // Create templated slide
  85. echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
  86. $currentSlide = createTemplatedSlide($objPHPPresentation);
  87. // Create a line chart (that should be inserted in a shape)
  88. echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
  89. $lineChart2 = clone $lineChart;
  90. $series2 = $lineChart2->getSeries();
  91. $series2[0]->getFont()->setSize(25);
  92. $series2[0]->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_TRIANGLE);
  93. $series2[0]->getMarker()->setSize(10);
  94. $lineChart2->setSeries($series2);
  95. // Create a shape (chart)
  96. echo date('H:i:s') . ' Create a shape (chart2)' . EOL;
  97. echo date('H:i:s') . ' Differences with previous : Values on right axis and Legend hidden' . EOL;
  98. $shape2 = clone $shape;
  99. $shape2->getLegend()->setVisible(false);
  100. $shape2->setName('PHPPresentation Weekly Downloads');
  101. $shape2->getTitle()->setText('PHPPresentation Weekly Downloads');
  102. $shape2->getPlotArea()->setType($lineChart2);
  103. $shape2->getPlotArea()->getAxisY()->setFormatCode('#,##0');
  104. $currentSlide->addShape($shape2);
  105. // Create templated slide
  106. echo EOL . date('H:i:s') . ' Create templated slide #3' . EOL;
  107. $currentSlide = createTemplatedSlide($objPHPPresentation);
  108. // Create a line chart (that should be inserted in a shape)
  109. echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
  110. $lineChart3 = clone $lineChart;
  111. $oGridLines1 = new \PhpOffice\PhpPresentation\Shape\Chart\Gridlines();
  112. $oGridLines1->getOutline()->setWidth(10);
  113. $oGridLines1->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  114. $oGridLines2 = new \PhpOffice\PhpPresentation\Shape\Chart\Gridlines();
  115. $oGridLines2->getOutline()->setWidth(1);
  116. $oGridLines2->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN));
  117. // Create a shape (chart)
  118. echo date('H:i:s') . ' Create a shape (chart3)' . EOL;
  119. echo date('H:i:s') . ' Feature : Gridlines' . EOL;
  120. $shape3 = clone $shape;
  121. $shape3->setName('Shape 3');
  122. $shape3->getTitle()->setText('Chart with Gridlines');
  123. $shape3->getPlotArea()->setType($lineChart3);
  124. $shape3->getPlotArea()->getAxisX()->setMajorGridlines($oGridLines1);
  125. $shape3->getPlotArea()->getAxisY()->setMinorGridlines($oGridLines2);
  126. $currentSlide->addShape($shape3);
  127. // Create templated slide
  128. echo EOL . date('H:i:s') . ' Create templated slide #4' . EOL;
  129. $currentSlide = createTemplatedSlide($objPHPPresentation);
  130. // Create a line chart (that should be inserted in a shape)
  131. echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
  132. $lineChart4 = clone $lineChart;
  133. $oOutlineAxisX = new \PhpOffice\PhpPresentation\Style\Outline();
  134. $oOutlineAxisX->setWidth(2);
  135. $oOutlineAxisX->getFill()->setFillType(Fill::FILL_SOLID);
  136. $oOutlineAxisX->getFill()->getStartColor()->setRGB('012345');
  137. $oOutlineAxisY = new \PhpOffice\PhpPresentation\Style\Outline();
  138. $oOutlineAxisY->setWidth(5);
  139. $oOutlineAxisY->getFill()->setFillType(Fill::FILL_SOLID);
  140. $oOutlineAxisY->getFill()->getStartColor()->setRGB('ABCDEF');
  141. // Create a shape (chart)
  142. echo date('H:i:s') . ' Create a shape (chart4)' . EOL;
  143. echo date('H:i:s') . ' Feature : Axis Outline' . EOL;
  144. $shape4 = clone $shape;
  145. $shape4->setName('Shape 4');
  146. $shape4->getTitle()->setText('Chart with Outline on Axis');
  147. $shape4->getPlotArea()->setType($lineChart4);
  148. $shape4->getPlotArea()->getAxisX()->setOutline($oOutlineAxisX);
  149. $shape4->getPlotArea()->getAxisY()->setOutline($oOutlineAxisY);
  150. $currentSlide->addShape($shape4);
  151. // Create templated slide
  152. echo EOL . date('H:i:s') . ' Create templated slide #5' . EOL;
  153. $currentSlide = createTemplatedSlide($objPHPPresentation);
  154. // Create a shape (chart)
  155. echo date('H:i:s') . ' Create a shape (chart5)' . EOL;
  156. echo date('H:i:s') . ' Feature : Gridlines' . EOL;
  157. $shape5 = clone $shape;
  158. $shape5->getPlotArea()->getAxisY()->setMinBounds(5);
  159. $shape5->getPlotArea()->getAxisY()->setMaxBounds(20);
  160. $currentSlide->addShape($shape5);
  161. // Save file
  162. echo EOL . write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
  163. if (!CLI) {
  164. include_once 'Sample_Footer.php';
  165. }