PHPPresentation
PHPPresentation copied to clipboard
Line charts not formatting series data as numbers
Hi, it seems like series data that I give to a Line() object does not format the values into numbers as they should be.
Because of this the following does not work:
$lineChart = new Line();
$seriesData = array('Monday' => 18, 'Tuesday' => 23, 'Wednesday' => 14, 'Thursday' => 12, 'Friday' => 20, 'Saturday' => 8, 'Sunday' => 10);
$series = new Series('example', $seriesData);
$series->setShowValue(false);
$series->setShowPercentage(true); // This does nothing
$series->setDlblNumFormat('0.00%'); // This does nothing
$lineChart->addSeries($series);
Also, the Y-axis labels aren't displaying as percentages either. Can you please help or make any suggestion?
When I open the generated .pptx file and right-click on the chart and select "Edit Data", I can see that the way it's saved in Excel is of type "General" which is probably exactly why this is happening. If I change it to "Number" everything starts working.
Thanks
Hi, I have a question for you. I'm using phppresentation with laravel 5.1 and i'm trying to make charts in my powerpoint. The problem i'm facing is that whatever i try, my powerpoint will always be broken and needs repairing.
I wondered if you you had the same problem and if you had, you could tell me how you solved it
Thanks
Hi @pascalzoet ,
I had the exact same problem and couldn't get anything to really work with the current dev-master branch. I switched to 0.8.0 and most things started working for me. Try it and let us know.
Hi @albertnel
Switched to version 0.8.0 and got the charts (finally) working. Thanks for the help!
@pascalzoet awesome, glad you got it working! :)
@albertnel @pascalzoet Thanks for answers. So that works with 0.8.0 but not with the develop branch ?
@Progi1984 So i tested this code on both version 0.8.0 and dev-master
$currentSlide = $objPHPPresentation->createSlide();
$seriesData = array(
'Monday' => 12,
'Tuesday' => 15,
'Wednesday' => 13,
'Thursday' => 17,
'Friday' => 14,
'Saturday' => 9,
'Sunday' => 7
);
$lineChart = new \PhpOffice\PhpPresentation\Shape\Chart\Type\Line();
$series = new \PhpOffice\PhpPresentation\Shape\Chart\Series('Downloads', $seriesData);
$series->setShowSeriesName(false);
$series->setShowValue(false);
$series->setShowLeaderLines(false);
$lineChart->addSeries($series);
$shape = $currentSlide->createChartShape();
$shape->setResizeProportional(false)->setHeight(100)->setWidth(200)->setOffsetX(200)->setOffsetY(200);
$shape->getTitle()->setVisible(false);
$shape->getPlotArea()->setType($lineChart);
$shape->getPlotArea()->getAxisY()->setFormatCode('#,##0');
$shape->getLegend()->setVisible(false);
$oWriterPPTX = \PhpOffice\PhpPresentation\IOFactory::createWriter($objPHPPresentation, 'PowerPoint2007');
$oWriterPPTX->save('/var/www/storage/app/powerpoint/test.pptx');`
On version 0.8.0 it works perfect. No repairing needed and i get the right chart.
https://imgur.com/a/AVuQ5
On version dev-master when i generated the same one and tried to open it, it instantly throws a repair error and after repairing its loses all his content.
Hope this helps out a bit.
Greats,