News
Creating a bar chart in a docx document with PHPDocX
- Jun 06, 2011
Creating a Bar Chart is easy: you just have to pass as parameters to the addChart the data array, the type as 'colChart' as well as some additional formating data.
Sample code:
require_once '../../classes/CreateDocx.inc';
$docx = new CreateDocx();
// Data and the legends
$colChartValues = array(
'legend' => array('Internet Explorer', 'Firefox', 'Chrome', 'Safari', 'Opera'),
'November 2010' => array('28.6', '44.0', '20.5', '4.0', '2.3'),
'December 2010' => array('27.5', '43.5', '22.4', '3.8', '2.2'),
'January 2011' => array('26.6', '42.8', '23.8', '4.0', '2.5')
);
// here you can give format to the Bar Chart
$paramsChart = array(
'data' => $colChartValues,
'type' => 'colChart',
'title' => 'W3C Browser Statistics',
'color' => 2,
'sizeX' => 15,
'sizeY' => 15,
'jc' => 'center',
'groupBar' => 'clustered',
'font' => 'Lucida Console'
);
$docx->addGraphic($paramsChart);
$docx->createDocx('example_bar_chart');