News
Pie charts with PHPDocX
- Sep 01, 2009
This information is outdated, please, refer to the addChart documentation for up to date info.
It is obvious that a “half decent” application to generate reports has to include a tool for the creation of charts and graphs on the fly, so PHPDOCX could not do less than that.
In fact PHPDOCX is a pretty sophisticated tool to that regard and as we show below is very simple to generate a nice chart from some data that could be extracted from a database, a spreadsheet or elsewhere.
In this example we will concentrate in creating a pie chart that plots the following sample data: Market Share Distribution by Country: Spain: 50 China: 10 USA: 40 Germany: 20
require_once('../classes/cCreateDocx.inc');
$objDocx = new cCreateDocx();
$arrDatos = array( 'Spain' => array(50), 'China' => array(10), 'USA' => array(40), 'Germany' => array(20));
$arrArgs = array('data' => $arrDatos, 'type' => 'pieChart', 'title' => 'Market Share Distribution by Country', 'showPercent' => 1 );
$objDocx->fAddGraphic($arrArgs);
$objDocx->fCreateDocx('simple_piechart');
Download example file
That generates this pie chart.
If you prefer a 3D version of this pie chart you need the Pro version but the required code is not much different:
require_once('../classes/cCreateDocx.inc');
$objDocx = new cCreateDocx();
$arrDatos = array( 'Spain' => array(50), 'China' => array(10), 'USA' => array(40), 'Germany' => array(20));
$arrArgs = array('data' => $arrDatos, 'type' => 'pie3DChart', 'title' => 'Market Share Distribution by Country', 'showPercent' => 1 );
$objDocx->fAddGraphic($arrArgs);
$objDocx->fCreateDocx('simple_piechart_3d');
Download example file