News
Two charts in a docx document with PHPdocx
- May 04, 2011
In this example we add a couple of charts inside a docx documents. The process for adding a chart in PHPdocx is simple: first you need to define the labels and info, next you define how will be the chart and at the end you construct the chart inside the documents.
require_once '../../classes/CreateDocx.inc';
$docx = new CreateDocx();
// First chart, a 3D Pie Chart
// Labels and info
$legends = array(
'legend1' => array(10, 11, 12),
'legend2' => array(0, 1, 2),
'legend3' => array(40, 41, 42)
);
// Chart's parameters
$args = array(
'data' => $legends,
'type' => 'pie3DChart',
'title' => 'Title first chart',
'cornerX' => 20, 'cornerY' => 20, 'cornerP' => 30,
'color' => 2,
'textWrap' => 0,
'sizeX' => 10, 'sizeY' => 10,
'jc' => 'left',
'showPercent' => 1,
'font' => 'Times New Roman'
);
// Construct the chart
$docx->addGraphic($args);
// This is a different chart: Colummns
$legends = array(
'0' => array('sequence 1', 'sequence 2', 'sequence 3'),
'Category 1' => array(9.3, 2.4, 2),
'Category 2' => array(2.5, 4.4, 1),
'Category 3' => array(3.5, 1.8, 0.5),
'Category 4' => array(1.5, 8, 1)
);
$args = array(
'data' => $legends,
'type' => 'colChart',
'title' => 'Title second chart',
'color' => 2,
'textWrap' => 0,
'sizeX' => 17, 'sizeY' => 7,
'jc' => 'center',
'font' => 'Arial'
);
$docx->addGraphic($args);
$docx->createDocx('example_chart');