Sample_05_Chart.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <?php
  2. include_once 'Sample_Header.php';
  3. use PhpOffice\PhpPresentation\PhpPresentation;
  4. use PhpOffice\PhpPresentation\Shape\Chart\Type\Area;
  5. use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
  6. use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
  7. use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
  8. use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie;
  9. use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
  10. use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
  11. use PhpOffice\PhpPresentation\Shape\Chart\Series;
  12. use PhpOffice\PhpPresentation\Style\Alignment;
  13. use PhpOffice\PhpPresentation\Style\Border;
  14. use PhpOffice\PhpPresentation\Style\Color;
  15. use PhpOffice\PhpPresentation\Style\Fill;
  16. use PhpOffice\PhpPresentation\Style\Shadow;
  17. function fnSlide_Area(PhpPresentation $objPHPPresentation) {
  18. global $oFill;
  19. global $oShadow;
  20. // Generate sample data for chart
  21. echo date('H:i:s') . ' Generate sample data for chart' . EOL;
  22. $seriesData = array(
  23. 'Monday' => 12,
  24. 'Tuesday' => 15,
  25. 'Wednesday' => 13,
  26. 'Thursday' => 17,
  27. 'Friday' => 14,
  28. 'Saturday' => 9,
  29. 'Sunday' => 7
  30. );
  31. // Create templated slide
  32. echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
  33. $currentSlide = createTemplatedSlide($objPHPPresentation);
  34. // Create a line chart (that should be inserted in a shape)
  35. echo date('H:i:s') . ' Create a area chart (that should be inserted in a chart shape)' . EOL;
  36. $areaChart = new Area();
  37. $series = new Series('Downloads', $seriesData);
  38. $series->setShowSeriesName(true);
  39. $series->setShowValue(true);
  40. $series->getFill()->setStartColor(new Color('FF93A9CE'));
  41. $series->setLabelPosition(Series::LABEL_INSIDEEND);
  42. $areaChart->addSeries($series);
  43. // Create a shape (chart)
  44. echo date('H:i:s') . ' Create a shape (chart)' . EOL;
  45. $shape = $currentSlide->createChartShape();
  46. $shape->getTitle()->setVisible(false);
  47. $shape->setName('PHPPresentation Daily Downloads')->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  48. $shape->setShadow($oShadow);
  49. $shape->setFill($oFill);
  50. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  51. $shape->getTitle()->setText('PHPPresentation Daily Downloads');
  52. $shape->getTitle()->getFont()->setItalic(true);
  53. $shape->getPlotArea()->setType($areaChart);
  54. $shape->getPlotArea()->getAxisX()->setTitle('Axis X');
  55. $shape->getPlotArea()->getAxisY()->setTitle('Axis Y');
  56. $shape->getView3D()->setRotationX(30);
  57. $shape->getView3D()->setPerspective(30);
  58. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  59. $shape->getLegend()->getFont()->setItalic(true);
  60. }
  61. function fnSlide_Bar(PhpPresentation $objPHPPresentation) {
  62. global $oFill;
  63. global $oShadow;
  64. // Create templated slide
  65. echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
  66. $currentSlide = createTemplatedSlide($objPHPPresentation);
  67. // Generate sample data for first chart
  68. echo date('H:i:s') . ' Generate sample data for chart'.EOL;
  69. $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
  70. $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
  71. // Create a bar chart (that should be inserted in a shape)
  72. echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)'.EOL;
  73. $barChart = new Bar();
  74. $barChart->setGapWidthPercent(158);
  75. $series1 = new Series('2009', $series1Data);
  76. $series1->setShowSeriesName(true);
  77. $series1->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4F81BD'));
  78. $series1->getFont()->getColor()->setRGB('00FF00');
  79. $series1->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
  80. $series2 = new Series('2010', $series2Data);
  81. $series2->setShowSeriesName(true);
  82. $series2->getFont()->getColor()->setRGB('FF0000');
  83. $series2->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFC0504D'));
  84. $series2->setLabelPosition(Series::LABEL_INSIDEEND);
  85. $barChart->addSeries($series1);
  86. $barChart->addSeries($series2);
  87. // Create a shape (chart)
  88. echo date('H:i:s') . ' Create a shape (chart)'.EOL;
  89. $shape = $currentSlide->createChartShape();
  90. $shape->setName('PHPPresentation Monthly Downloads')
  91. ->setResizeProportional(false)
  92. ->setHeight(550)
  93. ->setWidth(700)
  94. ->setOffsetX(120)
  95. ->setOffsetY(80);
  96. $shape->setShadow($oShadow);
  97. $shape->setFill($oFill);
  98. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  99. $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
  100. $shape->getTitle()->getFont()->setItalic(true);
  101. $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
  102. $shape->getPlotArea()->getAxisX()->setTitle('Month');
  103. $shape->getPlotArea()->getAxisY()->getFont()->getColor()->setRGB('00FF00');
  104. $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
  105. $shape->getPlotArea()->setType($barChart);
  106. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  107. $shape->getLegend()->getFont()->setItalic(true);
  108. }
  109. function fnSlide_BarHorizontal(PhpPresentation $objPHPPresentation) {
  110. global $oFill;
  111. global $oShadow;
  112. // Create a bar chart (that should be inserted in a shape)
  113. echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) '.EOL;
  114. $barChartHorz = clone $objPHPPresentation->getSlide(1)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
  115. $barChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
  116. // Create templated slide
  117. echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
  118. $currentSlide = createTemplatedSlide($objPHPPresentation);
  119. // Create a shape (chart)
  120. echo date('H:i:s') . ' Create a shape (chart)'.EOL;
  121. $shape = $currentSlide->createChartShape();
  122. $shape->setName('PHPPresentation Monthly Downloads')
  123. ->setResizeProportional(false)
  124. ->setHeight(550)
  125. ->setWidth(700)
  126. ->setOffsetX(120)
  127. ->setOffsetY(80);
  128. $shape->setShadow($oShadow);
  129. $shape->setFill($oFill);
  130. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  131. $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
  132. $shape->getTitle()->getFont()->setItalic(true);
  133. $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
  134. $shape->getPlotArea()->getAxisX()->setTitle('Month');
  135. $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
  136. $shape->getPlotArea()->setType($barChartHorz);
  137. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  138. $shape->getLegend()->getFont()->setItalic(true);
  139. }
  140. function fnSlide_BarStacked(PhpPresentation $objPHPPresentation) {
  141. global $oFill;
  142. global $oShadow;
  143. // Create templated slide
  144. echo EOL . date( 'H:i:s' ) . ' Create templated slide' . EOL;
  145. $currentSlide = createTemplatedSlide( $objPHPPresentation );
  146. // Generate sample data for first chart
  147. echo date( 'H:i:s' ) . ' Generate sample data for chart' . EOL;
  148. $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
  149. $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
  150. $series3Data = array('Jan' => 233, 'Feb' => 146, 'Mar' => 238, 'Apr' => 175, 'May' => 108, 'Jun' => 257, 'Jul' => 199, 'Aug' => 201, 'Sep' => 88, 'Oct' => 147, 'Nov' => 287, 'Dec' => 105);
  151. // Create a bar chart (that should be inserted in a shape)
  152. echo date( 'H:i:s' ) . ' Create a stacked bar chart (that should be inserted in a chart shape)' . EOL;
  153. $StackedBarChart = new Bar();
  154. $series1 = new Series( '2009', $series1Data );
  155. $series1->setShowSeriesName( false );
  156. $series1->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF4F81BD' ) );
  157. $series1->getFont()->getColor()->setRGB( '00FF00' );
  158. $series1->setShowValue( true );
  159. $series1->setShowPercentage( false );
  160. $series2 = new Series( '2010', $series2Data );
  161. $series2->setShowSeriesName( false );
  162. $series2->getFont()->getColor()->setRGB( 'FF0000' );
  163. $series2->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FFC0504D' ) );
  164. $series2->setShowValue( true );
  165. $series2->setShowPercentage( false );
  166. $series3 = new Series( '2011', $series3Data );
  167. $series3->setShowSeriesName( false );
  168. $series3->getFont()->getColor()->setRGB( 'FF0000' );
  169. $series3->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF804DC0' ) );
  170. $series3->setShowValue( true );
  171. $series3->setShowPercentage( false );
  172. $StackedBarChart->addSeries( $series1 );
  173. $StackedBarChart->addSeries( $series2 );
  174. $StackedBarChart->addSeries( $series3 );
  175. $StackedBarChart->setBarGrouping( Bar::GROUPING_STACKED );
  176. // Create a shape (chart)
  177. echo date( 'H:i:s' ) . ' Create a shape (chart)' . EOL;
  178. $shape = $currentSlide->createChartShape();
  179. $shape->setName( 'PHPPresentation Monthly Downloads' )
  180. ->setResizeProportional( false )
  181. ->setHeight( 550 )
  182. ->setWidth( 700 )
  183. ->setOffsetX( 120 )
  184. ->setOffsetY( 80 );
  185. $shape->setShadow( $oShadow );
  186. $shape->setFill( $oFill );
  187. $shape->getBorder()->setLineStyle( Border::LINE_SINGLE );
  188. $shape->getTitle()->setText( 'PHPPresentation Monthly Downloads' );
  189. $shape->getTitle()->getFont()->setItalic( true );
  190. $shape->getTitle()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_RIGHT );
  191. $shape->getPlotArea()->getAxisX()->setTitle( 'Month' );
  192. $shape->getPlotArea()->getAxisY()->setTitle( 'Downloads' );
  193. $shape->getPlotArea()->setType( $StackedBarChart );
  194. $shape->getLegend()->getBorder()->setLineStyle( Border::LINE_SINGLE );
  195. $shape->getLegend()->getFont()->setItalic( true );
  196. }
  197. function fnSlide_BarPercentStacked(PhpPresentation $objPHPPresentation) {
  198. global $oFill;
  199. global $oShadow;
  200. // Create templated slide
  201. echo EOL . date( 'H:i:s' ) . ' Create templated slide' . EOL;
  202. $currentSlide = createTemplatedSlide( $objPHPPresentation );
  203. // Generate sample data for first chart
  204. echo date( 'H:i:s' ) . ' Generate sample data for chart' . EOL;
  205. $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
  206. $Series1Sum = array_sum($series1Data);
  207. foreach ($series1Data as $CatName => $Value) {
  208. $series1Data[$CatName]= round($Value / $Series1Sum, 2);
  209. }
  210. $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
  211. $Series2Sum = array_sum($series2Data);
  212. foreach ($series2Data as $CatName => $Value) {
  213. $series2Data[$CatName] = round($Value / $Series2Sum, 2);
  214. }
  215. $series3Data = array('Jan' => 233, 'Feb' => 146, 'Mar' => 238, 'Apr' => 175, 'May' => 108, 'Jun' => 257, 'Jul' => 199, 'Aug' => 201, 'Sep' => 88, 'Oct' => 147, 'Nov' => 287, 'Dec' => 105);
  216. $Series3Sum = array_sum( $series3Data );
  217. foreach ($series3Data as $CatName => $Value) {
  218. $series3Data[$CatName] = round($Value / $Series3Sum,2);
  219. }
  220. // Create a bar chart (that should be inserted in a shape)
  221. echo date( 'H:i:s' ) . ' Create a percent stacked horizontal bar chart (that should be inserted in a chart shape)' . EOL;
  222. $PercentStackedBarChartHoriz = new Bar();
  223. $series1 = new Series( '2009', $series1Data );
  224. $series1->setShowSeriesName( false );
  225. $series1->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF4F81BD' ) );
  226. $series1->getFont()->getColor()->setRGB( '00FF00' );
  227. $series1->setShowValue( true );
  228. $series1->setShowPercentage( false );
  229. // Set Data Label Format For Chart To Display Percent
  230. $series1->setDlblNumFormat( '#%' );
  231. $series2 = new Series( '2010', $series2Data );
  232. $series2->setShowSeriesName( false );
  233. $series2->getFont()->getColor()->setRGB( 'FF0000' );
  234. $series2->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FFC0504D' ) );
  235. $series2->setShowValue( true );
  236. $series2->setShowPercentage( false );
  237. $series2->setDlblNumFormat( '#%' );
  238. $series3 = new Series( '2011', $series3Data );
  239. $series3->setShowSeriesName( false );
  240. $series3->getFont()->getColor()->setRGB( 'FF0000' );
  241. $series3->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF804DC0' ) );
  242. $series3->setShowValue( true );
  243. $series3->setShowPercentage( false );
  244. $series3->setDlblNumFormat( '#%' );
  245. $PercentStackedBarChartHoriz->addSeries( $series1 );
  246. $PercentStackedBarChartHoriz->addSeries( $series2 );
  247. $PercentStackedBarChartHoriz->addSeries( $series3 );
  248. $PercentStackedBarChartHoriz->setBarGrouping( Bar::GROUPING_PERCENTSTACKED );
  249. $PercentStackedBarChartHoriz->setBarDirection( Bar3D::DIRECTION_HORIZONTAL );
  250. // Create a shape (chart)
  251. echo date( 'H:i:s' ) . ' Create a shape (chart)' . EOL;
  252. $shape = $currentSlide->createChartShape();
  253. $shape->setName( 'PHPPresentation Monthly Downloads' )
  254. ->setResizeProportional( false )
  255. ->setHeight( 550 )
  256. ->setWidth( 700 )
  257. ->setOffsetX( 120 )
  258. ->setOffsetY( 80 );
  259. $shape->setShadow( $oShadow );
  260. $shape->setFill( $oFill );
  261. $shape->getBorder()->setLineStyle( Border::LINE_SINGLE );
  262. $shape->getTitle()->setText( 'PHPPresentation Monthly Downloads' );
  263. $shape->getTitle()->getFont()->setItalic( true );
  264. $shape->getTitle()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_RIGHT );
  265. $shape->getPlotArea()->getAxisX()->setTitle( 'Month' );
  266. $shape->getPlotArea()->getAxisY()->setTitle( 'Downloads' );
  267. $shape->getPlotArea()->setType( $PercentStackedBarChartHoriz );
  268. $shape->getLegend()->getBorder()->setLineStyle( Border::LINE_SINGLE );
  269. $shape->getLegend()->getFont()->setItalic( true );
  270. }
  271. function fnSlide_Bar3D(PhpPresentation $objPHPPresentation) {
  272. global $oFill;
  273. global $oShadow;
  274. // Create templated slide
  275. echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
  276. $currentSlide = createTemplatedSlide($objPHPPresentation);
  277. // Generate sample data for first chart
  278. echo date('H:i:s') . ' Generate sample data for chart'.EOL;
  279. $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
  280. $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
  281. // Create a bar chart (that should be inserted in a shape)
  282. echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)'.EOL;
  283. $bar3DChart = new Bar3D();
  284. $series1 = new Series('2009', $series1Data);
  285. $series1->setShowSeriesName(true);
  286. $series1->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4F81BD'));
  287. $series1->getFont()->getColor()->setRGB('00FF00');
  288. $series1->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
  289. $series2 = new Series('2010', $series2Data);
  290. $series2->setShowSeriesName(true);
  291. $series2->getFont()->getColor()->setRGB('FF0000');
  292. $series2->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFC0504D'));
  293. $bar3DChart->addSeries($series1);
  294. $bar3DChart->addSeries($series2);
  295. // Create a shape (chart)
  296. echo date('H:i:s') . ' Create a shape (chart)'.EOL;
  297. $shape = $currentSlide->createChartShape();
  298. $shape->setName('PHPPresentation Monthly Downloads')
  299. ->setResizeProportional(false)
  300. ->setHeight(550)
  301. ->setWidth(700)
  302. ->setOffsetX(120)
  303. ->setOffsetY(80);
  304. $shape->setShadow($oShadow);
  305. $shape->setFill($oFill);
  306. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  307. $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
  308. $shape->getTitle()->getFont()->setItalic(true);
  309. $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
  310. $shape->getPlotArea()->getAxisX()->setTitle('Month');
  311. $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
  312. $shape->getPlotArea()->setType($bar3DChart);
  313. $shape->getView3D()->setRightAngleAxes(true);
  314. $shape->getView3D()->setRotationX(20);
  315. $shape->getView3D()->setRotationY(20);
  316. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  317. $shape->getLegend()->getFont()->setItalic(true);
  318. }
  319. function fnSlide_Bar3DHorizontal(PhpPresentation $objPHPPresentation) {
  320. global $oFill;
  321. global $oShadow;
  322. // Create a bar chart (that should be inserted in a shape)
  323. echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) '.EOL;
  324. $bar3DChartHorz = clone $objPHPPresentation->getSlide(5)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
  325. $bar3DChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
  326. // Create templated slide
  327. echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
  328. $currentSlide = createTemplatedSlide($objPHPPresentation);
  329. // Create a shape (chart)
  330. echo date('H:i:s') . ' Create a shape (chart)'.EOL;
  331. $shape = $currentSlide->createChartShape();
  332. $shape->setName('PHPPresentation Monthly Downloads')
  333. ->setResizeProportional(false)
  334. ->setHeight(550)
  335. ->setWidth(700)
  336. ->setOffsetX(120)
  337. ->setOffsetY(80);
  338. $shape->setShadow($oShadow);
  339. $shape->setFill($oFill);
  340. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  341. $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
  342. $shape->getTitle()->getFont()->setItalic(true);
  343. $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
  344. $shape->getPlotArea()->getAxisX()->setTitle('Month');
  345. $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
  346. $shape->getPlotArea()->setType($bar3DChartHorz);
  347. $shape->getView3D()->setRightAngleAxes(true);
  348. $shape->getView3D()->setRotationX(20);
  349. $shape->getView3D()->setRotationY(20);
  350. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  351. $shape->getLegend()->getFont()->setItalic(true);
  352. }
  353. function fnSlide_Pie3D(PhpPresentation $objPHPPresentation) {
  354. global $oFill;
  355. global $oShadow;
  356. // Create templated slide
  357. echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
  358. $currentSlide = createTemplatedSlide($objPHPPresentation);
  359. // Generate sample data for second chart
  360. echo date('H:i:s') . ' Generate sample data for chart'.EOL;
  361. $seriesData = array('Monday' => 12, 'Tuesday' => 15, 'Wednesday' => 13, 'Thursday' => 17, 'Friday' => 14, 'Saturday' => 9, 'Sunday' => 7);
  362. // Create a pie chart (that should be inserted in a shape)
  363. echo date('H:i:s') . ' Create a pie chart (that should be inserted in a chart shape)'.EOL;
  364. $pie3DChart = new Pie3D();
  365. $pie3DChart->setExplosion(20);
  366. $series = new Series('Downloads', $seriesData);
  367. $series->setShowSeriesName(true);
  368. $series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8'));
  369. $series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFAB4744'));
  370. $series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8AA64F'));
  371. $series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF725990'));
  372. $series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4299B0'));
  373. $series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFDC853E'));
  374. $series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF93A9CE'));
  375. $pie3DChart->addSeries($series);
  376. // Create a shape (chart)
  377. echo date('H:i:s') . ' Create a shape (chart)'.EOL;
  378. $shape = $currentSlide->createChartShape();
  379. $shape->setName('PHPPresentation Daily Downloads')
  380. ->setResizeProportional(false)
  381. ->setHeight(550)
  382. ->setWidth(700)
  383. ->setOffsetX(120)
  384. ->setOffsetY(80);
  385. $shape->setShadow($oShadow);
  386. $shape->setFill($oFill);
  387. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  388. $shape->getTitle()->setText('PHPPresentation Daily Downloads');
  389. $shape->getTitle()->getFont()->setItalic(true);
  390. $shape->getPlotArea()->setType($pie3DChart);
  391. $shape->getView3D()->setRotationX(30);
  392. $shape->getView3D()->setPerspective(30);
  393. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  394. $shape->getLegend()->getFont()->setItalic(true);
  395. }
  396. function fnSlide_Pie(PhpPresentation $objPHPPresentation) {
  397. global $oFill;
  398. global $oShadow;
  399. // Create templated slide
  400. echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
  401. $currentSlide = createTemplatedSlide($objPHPPresentation);
  402. // Generate sample data for second chart
  403. echo date('H:i:s') . ' Generate sample data for chart'.EOL;
  404. $seriesData = array('Monday' => 18, 'Tuesday' => 23, 'Wednesday' => 14, 'Thursday' => 12, 'Friday' => 20, 'Saturday' => 8, 'Sunday' => 10);
  405. // Create a pie chart (that should be inserted in a shape)
  406. echo date('H:i:s') . ' Create a non-3D pie chart (that should be inserted in a chart shape)'.EOL;
  407. $pieChart = new Pie();
  408. $pieChart->setExplosion(15);
  409. $series = new Series('Downloads', $seriesData);
  410. $series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF7CB5EC'));
  411. $series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF434348'));
  412. $series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF90ED7D'));
  413. $series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF7A35C'));
  414. $series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8085E9'));
  415. $series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF15C80'));
  416. $series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE4D354'));
  417. $series->setShowPercentage( true );
  418. $series->setShowValue( false );
  419. $series->setShowSeriesName( false );
  420. $series->setShowCategoryName( true );
  421. $series->setDlblNumFormat('%d');
  422. $pieChart->addSeries($series);
  423. // Create a shape (chart)
  424. echo date('H:i:s') . ' Create a shape (chart)'.EOL;
  425. $shape = $currentSlide->createChartShape();
  426. $shape->setName('PHPPresentation Daily Downloads')
  427. ->setResizeProportional(false)
  428. ->setHeight(550)
  429. ->setWidth(700)
  430. ->setOffsetX(120)
  431. ->setOffsetY(80);
  432. $shape->setShadow($oShadow);
  433. $shape->setFill($oFill);
  434. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  435. $shape->getTitle()->setText('PHPPresentation Daily Downloads');
  436. $shape->getTitle()->getFont()->setItalic(true);
  437. $shape->getPlotArea()->setType($pieChart);
  438. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  439. $shape->getLegend()->getFont()->setItalic(true);
  440. }
  441. function fnSlide_Scatter(PhpPresentation $objPHPPresentation) {
  442. global $oFill;
  443. global $oShadow;
  444. // Create templated slide
  445. echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
  446. $currentSlide = createTemplatedSlide($objPHPPresentation); // local function
  447. // Generate sample data for fourth chart
  448. echo date('H:i:s') . ' Generate sample data for chart'.EOL;
  449. $seriesData = array('Monday' => 0.1, 'Tuesday' => 0.33333, 'Wednesday' => 0.4444, 'Thursday' => 0.5, 'Friday' => 0.4666, 'Saturday' => 0.3666, 'Sunday' => 0.1666);
  450. // Create a scatter chart (that should be inserted in a shape)
  451. echo date('H:i:s') . ' Create a scatter chart (that should be inserted in a chart shape)'.EOL;
  452. $lineChart = new Scatter();
  453. $series = new Series('Downloads', $seriesData);
  454. $series->setShowSeriesName(true);
  455. $series->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_DASH);
  456. $series->getMarker()->setSize(10);
  457. $lineChart->addSeries($series);
  458. // Create a shape (chart)
  459. echo date('H:i:s') . ' Create a shape (chart)'.EOL;
  460. $shape = $currentSlide->createChartShape();
  461. $shape->setName('PHPPresentation Daily Download Distribution')
  462. ->setResizeProportional(false)
  463. ->setHeight(550)
  464. ->setWidth(700)
  465. ->setOffsetX(120)
  466. ->setOffsetY(80);
  467. $shape->setShadow($oShadow);
  468. $shape->setFill($oFill);
  469. $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
  470. $shape->getTitle()->setText('PHPPresentation Daily Downloads');
  471. $shape->getTitle()->getFont()->setItalic(true);
  472. $shape->getPlotArea()->setType($lineChart);
  473. $shape->getView3D()->setRotationX(30);
  474. $shape->getView3D()->setPerspective(30);
  475. $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
  476. $shape->getLegend()->getFont()->setItalic(true);
  477. }
  478. // Create new PHPPresentation object
  479. echo date('H:i:s') . ' Create new PHPPresentation object'.EOL;
  480. $objPHPPresentation = new PhpPresentation();
  481. // Set properties
  482. echo date('H:i:s') . ' Set properties'.EOL;
  483. $objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
  484. ->setLastModifiedBy('PHPPresentation Team')
  485. ->setTitle('Sample 07 Title')
  486. ->setSubject('Sample 07 Subject')
  487. ->setDescription('Sample 07 Description')
  488. ->setKeywords('office 2007 openxml libreoffice odt php')
  489. ->setCategory('Sample Category');
  490. // Remove first slide
  491. echo date('H:i:s') . ' Remove first slide'.EOL;
  492. $objPHPPresentation->removeSlideByIndex(0);
  493. // Set Style
  494. $oFill = new Fill();
  495. $oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
  496. $oShadow = new Shadow();
  497. $oShadow->setVisible(true)->setDirection(45)->setDistance(10);
  498. fnSlide_Area($objPHPPresentation);
  499. fnSlide_Bar($objPHPPresentation);
  500. fnSlide_BarStacked($objPHPPresentation);
  501. fnSlide_BarPercentStacked($objPHPPresentation);
  502. fnSlide_BarHorizontal($objPHPPresentation);
  503. fnSlide_Bar3D($objPHPPresentation);
  504. fnSlide_Bar3DHorizontal($objPHPPresentation);
  505. fnSlide_Pie3D($objPHPPresentation);
  506. fnSlide_Pie($objPHPPresentation);
  507. fnSlide_Scatter($objPHPPresentation);
  508. // Save file
  509. echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
  510. if (!CLI) {
  511. include_once 'Sample_Footer.php';
  512. }