News
How to include a chart in a Word template with PHPDocX
- Jun 06, 2011
You may replace a placeholder variable by a chart within a Word document with the help of the PHPDocX addTemplate variable method.
An example follows where the placeholder variable 'PIECHART' is replaced by an actual 3D pie chart:
require_once '../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$docx->addTemplate('../files/TemplateChart.docx');
$legends = array(
'legend1' => array(10, 11, 12),
'legend2' => array(30, 21, 12),
'legend3' => array(40, 41, 42)
);
$paramsChart =
array(
'data' => $legends,
// Use 'pieChart' if you need a classic plain Pie Chart
'type' => 'pie3DChart',
'title' => 'Title',
'cornerX' => 20,
'cornerY' => 20,
'cornerP' => 30,
'color' => 2,
'textWrap' => 0,
'sizeX' => 10,
'sizeY' => 10,
'jc' => 'right',
'showPercent' => 1,
'font' => 'Times New Roman'
);
$docx->addTemplateChart('PIECHART', $paramsChart);
$docx->createDocx('template_chart');