addChart
- getTemplateVariables
- getTemplateVariablesType
- removeVariableAudio
- removeVariableImage
- removeVariableText
- removeVariableVideo
- replaceVariableAudio
- replaceVariableHtml
- replaceVariableImage
- replaceVariableList
- replaceVariablePptxFragment
- replaceVariableTable
- replaceVariableText
- replaceVariableVideo
- setTemplateSymbol
addChart

Inserts a chart into the PowerPoint presentation.
Description
public addChart($chart, $position, $chartData, $chartStyles = array(), $options = array())
This method allows the insertion of a chart into the PowerPoint presentation.
This method also allows adding trendlines, grids, labels and many other chart features.
Parameters
chart
Chart type:
- area
- area3D
- bar
- bar3D, bar3DCone, bar3DCylinder, bar3DPyramid
- bubble
- col
- col3D, col3DCone, col3DCylinder, col3DPyramid
- doughnut
- line
- line3D
- ofPie
- pie
- pie3D
- radar
- scatter
- surface
position
Key | Type | Description |
---|---|---|
new | array |
A new position is generated.
|
chartData
Chart data array: legends, labels and values of the chart.
chartStyles
Key | Type | Description |
---|---|---|
axPos | array | Position of the axis (r, l, t, b). Each value of the array for each position (if a value if null avoids adding it). |
color | int | Color scheme. |
font | string | The font to be used. Arial, Calibri... |
formatCode | string | Number format. |
formatDataLabels | array | Possible keys and values are:
|
haxLabel | string | Label for the horizontal axis. |
haxLabelDisplay | string | How to display the label of the horizontal axis. Possible values are: vertical, horizontal, rotated. |
hgrid | int | Horizontal grid. Possible values are:
|
majorUnit | float | Major unit value for bar, col and line charts. |
minorUnit | float | Minor unit value for bar, col and line charts. |
orientation | array | Orientation of the axis, from min to max (minMax) or max to min (maxMin). Each value of the array for each axis (if a value if null avoids adding it). |
scalingMax | float | Scaling max value for bar, col and line charts. |
scalingMin | float | Scaling max value for for bar, col and line charts. |
stylesTitle | array | Possible keys and values are:
|
tickLblPos | string | Tick label position (nextTo, high, low, none). If string, uses default values. If array, sets a value for each position. |
title | string | The chart title (if any). |
vaxLabel | string | Label for the vertical axis. |
vaxLabelDisplay | string | How to display the label of the horizontal axis. Possible values are: vertical, horizontal, rotated. |
vgrid | int | Vertical grid. Possible values are:
|
The available parameters to display legends and data include:
Key | Type | Description |
---|---|---|
legendOverlay | bool | If true the legend may overlay the chart. |
legendPos | string | The possible values are:
|
showCategory | bool | If true shows the categories inside the chart. |
showLegendKey | bool | If true shows the legend values. |
showPercent | bool | If true shows the percentage values. |
showSeries | bool | If true shows the series values. |
showTable | bool | If true shows the chart data in an associated table. |
showValue | bool | If true shows the chart data values. |
trendline | array | Adds trendlines. Compatible with line, bar, col and area 2D charts. Possible keys and values are:
|
Further configuration options for specific chart types are:
Key | Type | Description |
---|---|---|
Bar and column charts | ||
gapWidth | int | Gap width. |
groupBar | string | Different ways to group data. Possible values are: clustered, stacked, percentStacked and standard. |
overlap | int | Overlap. |
Pie and doughnut charts | ||
explosion | int | Distance between the different values. |
holeSize | int | Size of the inner hole (only doughnut charts). |
Line charts | ||
smooth | mixed | If true it smooths the line. '0' forces disabling it |
symbol | string | The possible symbol values are:
|
symbolSize | int | The size of the symbol used. From 1 to 73. |
Additional available options for 3D charts:
Key | Type | Description |
---|---|---|
perspective | int | Perspective angle. Angles beyond 25 degrees provoke a big distortion in the 3D chart representation. |
rotX | int | Rotation angle with respect to the vertical axis. Standard values are between 10 and 20 degrees. |
rotY | int | Rotation angle with respect to the horizontal axis. Standard values are between 10 and 20 degrees. |
Theme options (Available in Premium licenses):
Key | Type | Description |
---|---|---|
chartArea | array | backgroundColor |
gridLines | array |
|
horizontalAxis | array |
|
legendArea | array |
|
plotArea | array | backgroundColor |
serDataLabels | array |
|
serRgbColors | array | series colors |
valueDataLabels | array |
|
valueRgbColors | array | values colors |
verticalAxis | array |
|
Exceptions
Chart type is not supported.
Code samples
x
1
require_once 'classes/CreatPptx.php';
2
3
$pptx = new CreatePptx(array('layout' => 'Blank'));
4
5
$position = array(
6
'coordinateX' => 2400000,
7
'coordinateY' => 2500000,
8
'sizeX' => 5000000,
9
'sizeY' => 2500000,
10
);
11
$dataChart = array(
12
'data' => array(
13
array(
14
'name' => 'data 1',
15
'values' => array(10),
16
),
17
array(
18
'name' => 'data 2',
19
'values' => array(20),
20
),
21
array(
22
'name' => 'data 3',
23
'values' => array(50),
24
),
25
array(
26
'name' => 'data 4',
27
'values' => array(25),
28
),
29
),
30
);
31
$stylesChart = array(
32
'color' => 2,
33
'showPercent' => 1,
34
);
35
$pptx->addChart('pie3D', $position, $dataChart, $stylesChart);
36
37
$pptx->savePptx('output');
38
37
1
require_once 'classes/CreatPptx.php';
2
3
$pptx = new CreatePptx(array('layout' => 'Blank'));
4
5
$position = array(
6
'coordinateX' => 2400000,
7
'coordinateY' => 2500000,
8
'sizeX' => 5000000,
9
'sizeY' => 2500000,
10
);
11
$dataChart = array(
12
'legend' => array('Legend 1', 'Legend 2', 'Legend 3'),
13
'data' => array(
14
array(
15
'name' => 'data 1',
16
'values' => array(10, 20, 5),
17
),
18
array(
19
'name' => 'data 2',
20
'values' => array(20, 60, 3),
21
),
22
array(
23
'name' => 'data 3',
24
'values' => array(50, 33, 7),
25
),
26
),
27
);
28
$stylesChart = array(
29
'color' => 2,
30
'legendOverlay' => false,
31
'hgrid' => 1,
32
'vgrid' => 2,
33
);
34
$pptx->addChart('bar', $position, $dataChart, $stylesChart);
35
36
$pptx->savePptx('output');
37
56
1
require_once 'classes/CreatPptx.php';
2
3
$pptx = new CreatePptx(array('layout' => 'Blank'));
4
5
$position = array(
6
'coordinateX' => 2400000,
7
'coordinateY' => 2500000,
8
'sizeX' => 5000000,
9
'sizeY' => 2500000,
10
);
11
$dataChart = array(
12
'legend' => array('Series 1', 'Series 2', 'Series 3'),
13
'data' => array(
14
array(
15
'name' => 'data 1',
16
'values' => array(10, 7, 5),
17
),
18
array(
19
'name' => 'data 2',
20
'values' => array(20, 60, 3),
21
),
22
array(
23
'name' => 'data 3',
24
'values' => array(50, 33, 7),
25
),
26
array(
27
'name' => 'data 4',
28
'values' => array(25, 0, 14),
29
),
30
),
31
'trendline' => array(
32
array(
33
'color' => '0000FF',
34
'type' => 'log',
35
'displayEquation' => true,
36
'displayRSquared' => true,
37
),
38
array(),
39
array(
40
'color' => '0000FF',
41
'type' => 'power',
42
'lineStyle' => 'dot',
43
),
44
),
45
);
46
$stylesChart = array(
47
'legendOverlay' => false,
48
'haxLabel' => 'X Axis',
49
'vaxLabel' => 'Y Axis',
50
'haxLabelDisplay' => 'horizontal',
51
'vaxLabelDisplay' => 'vertical',
52
);
53
$pptx->addChart('line', $position, $dataChart, $stylesChart);
54
55
$pptx->savePptx('output');
56
51
1
require_once 'classes/CreatPptx.php';
2
3
$pptx = new CreatePptx(array('layout' => 'Blank'));
4
5
$position = array(
6
'coordinateX' => 2400000,
7
'coordinateY' => 2500000,
8
'sizeX' => 5000000,
9
'sizeY' => 2500000,
10
);
11
$dataChart = array(
12
'legend' => array('Series 1', 'Series 2', 'Series 3'),
13
'data' => array(
14
array(
15
'name' => 'data 1',
16
'values' => array(10, 7, 5),
17
),
18
array(
19
'name' => 'data 2',
20
'values' => array(20, 60, 3),
21
),
22
array(
23
'name' => 'data 3',
24
'values' => array(50, 33, 7),
25
),
26
array(
27
'name' => 'data 4',
28
'values' => array(25, 0, 14),
29
),
30
),
31
);
32
$stylesChart = array(
33
'color' => 3,
34
'legendPos' => 'b',
35
'legendOverlay' => false,
36
'hgrid' => 3,
37
'vgrid' => 0,
38
'groupBar' => 'stacked',
39
'theme' => array(
40
'serRgbColors' => array(null, 'FF00FF', '00FFFF'),
41
'valueRgbColors' => array(
42
array('FF0000'),
43
null,
44
array(null, null, '00FF00', '0000FF'),
45
),
46
),
47
);
48
$pptx->addChart('col', $position, $dataChart, $stylesChart);
49
50
$pptx->savePptx('output');
51
Release notes
- phppptx 3.5:
- set custom title layout.
- apply font styles to series and values labels.
- valueDataLabels option.
- phppptx 3.0:
- ofPie chart type.
- apply custom colors to lines.
- phppptx 2.5:
- bubble, radar, scatter and surface chart types.
- phppptx 1.0:
- new method.