Reputation: 2173
I know how to add charts on PHPExcel, but I also need to insert charts on a docx file. Is it possible to manipulate charts with phpoffice/phpword?
If it's not possible, do you know a good library for the job?
Upvotes: 4
Views: 6315
Reputation: 498
It's not actually possible to add chart in a PHPWord Document. But the feature is in the pipe (follow this ticket #123).
But you can use of one of some libraries used (at the moment and in the future) by PHPExcel : PHP Charting Libraries . Actually, PHPExcel just use JpGraph for rendering some graphs.
Upvotes: 2
Reputation: 909
You can add a chart, but its a bit limited and there are some hard codings in what's been created so far.
Example of what you can do: http://elumina.co/libs/PHPWord-master/samples/Sample_32_Chart.php
Source Code:https://github.com/PHPOffice/PHPWord/blob/master/samples/Sample_32_Chart.php
Some modification is needed to the classes to get certain graph options to work as these options were hard coded https://github.com/PHPOffice/PHPWord/issues/957
Can't edit the data https://github.com/PHPOffice/PHPWord/issues/956
Upvotes: 0
Reputation: 325
Some example from official github, hope this could answer your question :)
PHPWord : https://github.com/PHPOffice/PHPWord/blob/master/samples/Sample_32_Chart.php
PHPExcel : https://github.com/PHPOffice/PHPExcel/tree/master/Examples
Upvotes: 2
Reputation: 287
Yes it is possible to add charts in phpoffice. The problem is the documentation hasn't been completed yet.
$chart = $section->addChart([$chartType], [$categories], [$series]);
$chart->getStyle() //For styling the chart
$chartTypes = 'pie' / 'doughnut' / 'bar' / 'column'/ 'line'/ 'area' / 'scatter' / 'radar';
//Example
$chart = $section->addChart('pie', array('A', 'B', 'C', 'D', 'E'), array(1, 3, 2, 5, 4));
Upvotes: 2
Reputation: 1191
I don't know the library, but you can probably generate image in php (use PHP GD or imagemagick for example) and insert generated image into docx file.
Upvotes: 1