shapes_chart.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. .. _shapes_chart:
  2. Charts
  3. ======
  4. To create a chart, use `createChartShape` method of Slide.
  5. Example:
  6. .. code-block:: php
  7. $chartShape = $slide->createChartShape();
  8. Parts
  9. -----
  10. Axis
  11. ^^^^
  12. You can define gridlines (minor and major) for each axis (X & Y).
  13. For each gridline, you can custom the width (in points), the fill type and the fill color.
  14. .. code-block:: php
  15. use \PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
  16. $oLine = new Line();
  17. $oGridLines = new Gridlines();
  18. $oGridLines->getOutline()->setWidth(10);
  19. $oGridLines->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  20. $oShape = $oSlide->createChartShape();
  21. $oShape->getPlotArea()->setType($oLine);
  22. $oShape->getPlotArea()->getAxisX()->setMajorGridlines($oGridLines);
  23. For Axis, you can define the min & max bounds with `setMinBounds` & `setMaxBounds` methods.
  24. For resetting them, you pass null as parameter to these methods.
  25. .. code-block:: php
  26. use \PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
  27. $oLine = new Line();
  28. $oShape = $oSlide->createChartShape();
  29. $oShape->getPlotArea()->setType($oLine);
  30. $oShape->getPlotArea()->getAxisX()->setMinBounds(0);
  31. $oShape->getPlotArea()->getAxisX()->setMaxBounds(200);
  32. You can define outline for each axis (X & Y).
  33. .. code-block:: php
  34. $oLine = new Line();
  35. $oShape = $oSlide->createChartShape();
  36. $oShape->getPlotArea()->setType($oLine);
  37. $oShape->getPlotArea()->getAxisX()->getOutline()->setWidth(10);
  38. $oShape->getPlotArea()->getAxisX()->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  39. For Axis Y, you can define tick mark with `setMinorTickMark` & `setMajorTickMark` methods.
  40. For resetting them, you pass Axis::TICK_MARK_NONE as parameter to these methods.
  41. .. code-block:: php
  42. use \PhpOffice\PhpPresentation\Shape\Chart\Axis;
  43. $oLine = new Line();
  44. $oShape = $oSlide->createChartShape();
  45. $oShape->getPlotArea()->setType($oLine);
  46. $oShape->getPlotArea()->getAxisY()->setMinorTickMark(Axis::TICK_MARK_NONE);
  47. $oShape->getPlotArea()->getAxisY()->setMajorTickMark(Axis::TICK_MARK_INSIDE);
  48. For Axis Y, you can define unit with `setMinorUnit` & `setMajorUnit` methods.
  49. For resetting them, you pass null as parameter to these methods.
  50. .. code-block:: php
  51. use \PhpOffice\PhpPresentation\Shape\Chart\Axis;
  52. $oLine = new Line();
  53. $oShape = $oSlide->createChartShape();
  54. $oShape->getPlotArea()->setType($oLine);
  55. $oShape->getPlotArea()->getAxisY()->setMinorUnit(null);
  56. $oShape->getPlotArea()->getAxisY()->setMajorUnit(0.05);
  57. You can define visibility for each axis (X & Y).
  58. .. code-block:: php
  59. $oLine = new Line();
  60. $oShape = $oSlide->createChartShape();
  61. $oShape->getPlotArea()->setType($oLine);
  62. $oShape->getPlotArea()->getAxisX()->setIsVisible(false);
  63. Title
  64. ^^^^^
  65. By default, the title of a chart is displayed.
  66. For hiding it, you define its visibility to false.
  67. .. code-block:: php
  68. $oLine = new Line();
  69. $oShape = $slide->createChartShape();
  70. $oShape->getPlotArea()->setType($oLine);
  71. // Hide the title
  72. $oShape->getTitle()->setVisible(false);
  73. Series
  74. ^^^^^^
  75. You can custom the font of a serie.
  76. .. code-block:: php
  77. $oSeries = new Series('Downloads', $seriesData);
  78. // Define the size
  79. $oSeries->getFont()->setSize(25);
  80. You can custom the marker of a serie, for Line & Scatter charts.
  81. .. code-block:: php
  82. use \PhpOffice\PhpPresentation\Shape\Chart\Marker;
  83. $oSeries = new Series('Downloads', $seriesData);
  84. $oMarker = $oSeries->getMarker();
  85. $oMarker->setSymbol(Marker::SYMBOL_DASH)->setSize(10);
  86. You can custom the line of a serie, for Line & Scatter charts.
  87. .. code-block:: php
  88. use \PhpOffice\PhpPresentation\Style\Outline;
  89. $oOutline = new Outline();
  90. // Define the color
  91. $oOutline->getFill()->setFillType(Fill::FILL_SOLID);
  92. $oOutline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW));
  93. // Define the width (in points)
  94. $oOutline->setWidth(2);
  95. $oSeries = new Series('Downloads', $seriesData);
  96. $oSeries->setOutline($oOutline);
  97. You can define the position of the data label.
  98. Each position is described in `MSDN <https://msdn.microsoft.com/en-us/library/mt459417(v=office.12).aspx>`_
  99. .. code-block:: php
  100. $oSeries = new Series('Downloads', $seriesData);
  101. $oSeries->setLabelPosition(Series::LABEL_INSIDEEND);
  102. You can define if some informations are displayed.
  103. .. code-block:: php
  104. $oSeries = new Series('Downloads', $seriesData);
  105. $oSeries->setSeparator(';');
  106. $oSeries->setShowCategoryName(true);
  107. $oSeries->setShowLeaderLines(true);
  108. $oSeries->setShowLegendKey(true);
  109. $oSeries->setShowPercentage(true);
  110. $oSeries->setShowSeriesName(true);
  111. $oSeries->setShowValue(true);
  112. View3D
  113. ^^^^^^
  114. For enabling the autoscale for a shape, you must reset the height percent.
  115. .. code-block:: php
  116. $oShape->getView3D()->setHeightPercent(null);
  117. Types
  118. -----
  119. Area
  120. ^^^^
  121. TODO
  122. Bar & Bar3D
  123. ^^^^^^^^^^^
  124. Gap Width
  125. """""""""
  126. You can define the gap width between bar or columns clusters. It is defined in percent.
  127. The default value is 150%. The value must be defined between 0 and 500.
  128. .. code-block:: php
  129. $oBarChart = new Bar();
  130. $oBarChart->setGapWidthPercent(250);
  131. Stacking
  132. """"""""
  133. You can stack multiples series in a same chart. After adding multiples series, you can define the bar grouping with `setBarGrouping` method of AbstractTypeBar.
  134. .. code-block:: php
  135. $oBarChart = new Bar();
  136. $oBarChart->addSeries($oSeries1);
  137. $oBarChart->addSeries($oSeries2);
  138. $oBarChart->addSeries($oSeries3);
  139. $oBarChart->setBarGrouping(Bar::GROUPING_CLUSTERED);
  140. // OR
  141. $oBarChart->setBarGrouping(Bar::GROUPING_STACKED);
  142. // OR
  143. $oBarChart->setBarGrouping(Bar::GROUPING_PERCENTSTACKED);
  144. - Bar::GROUPING_CLUSTERED
  145. .. image:: images/chart_columns_52x60.png
  146. :width: 120px
  147. :alt: Bar::GROUPING_CLUSTERED
  148. - Bar::GROUPING_STACKED
  149. .. image:: images/chart_columnstack_52x60.png
  150. :width: 120px
  151. :alt: Bar::GROUPING_STACKED
  152. - Bar::GROUPING_PERCENTSTACKED
  153. .. image:: images/chart_columnpercent_52x60.png
  154. :width: 120px
  155. :alt: Bar::GROUPING_PERCENTSTACKED
  156. Line
  157. ^^^^
  158. TODO
  159. Pie & Pie3D
  160. ^^^^^^^^^^^
  161. TODO
  162. Scatter
  163. ^^^^^^^
  164. TODO