Practical phpxlsx
Charts
Working with charts is as easy as with pictures. You just need to choose the chart type to insert and add the values and legends.
There are 2D and 3D graphic available with many formats: bar, col, doughnut, line, pie...
Premium licenses include additional options to assign sophisticated styles such as defining custom and individual colors for series and values, adding color backgrounds and applying styles to axes.
For adding charts in the active sheet, call addChart:
This method includes the following parameters:
- $chart: chart type (bar, bar3D, col, col3D, doughnut, line, line3D, pie, pie3D...)
- $position: cell position in the active sheet (A1, C3, AB7...)
- $options: array to set values, legends, settings...
For example, to add a pie chart:
Legends, labels and values used to generate the chart must exist in the XLSX. In this sample, the addCell method inserts those values, but other methods and existing contents in templates can also be called.
Individual cell positions and cell range positions can be used to add legends, labels and values to charts. The following code uses cell ranges to add chart data:
The 'color' option of the addChart method sets a color scheme included in Excel.
Premium licenses include a theme option to assign more advanced styles such as defining custom and individual colors for series and values, adding color backgrounds and applying styles to axes.