When using adding charts to a PHPPresentation document it always needs repairing to open it. When repaired everything looks fine. If I don't include charts then the document opens without problems.
Not sure what I'm missing. Here's my function to add a chart:
function fnSlide_Bar(PhpPresentation $objPHPPresentation, $title, $audit_id, $query, $data = 'rows') {
global $wpdb;
// Create templated slide
$currentSlide = $objPHPPresentation->createSlide();
// Get data for chart
$seriesData = array();
$results = $wpdb->get_results("CALL {$query}({$audit_id})", ARRAY_A);
if ($data == 'rows') {
foreach ($results as $row) {
$seriesData[ str_replace(' & ',' and ', $row['label']) ] = (int)$row['value'];
}
} else {
$results = reset($results);
foreach ($results as $key => $result) {
$seriesData[ str_replace(' & ',' and ', $key) ] = (int)$result;
}
}
// Create a bar chart (that should be inserted in a shape)
$barChart = new PhpOffice\PhpPresentation\Shape\Chart\Type\Bar();
$barChart->setGapWidthPercent(158);
$series = new PhpOffice\PhpPresentation\Shape\Chart\Series('data', $seriesData);
$series->setShowSeriesName(false);
$series->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFafca0b'));
$series->getFont()->getColor()->setRGB('00FF00');
$series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFf39200'));
$series->setShowLegendKey(false);
$barChart->addSeries($series);
// Create a shape (chart)
$shape = $currentSlide->createChartShape();
$shape->setName($title)
->setResizeProportional(false)
->setHeight(550)
->setWidth(700)
->setOffsetX(120)
->setOffsetY(80);
$shape->getTitle()->setText($title);
$shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
$shape->getPlotArea()->setType($barChart);
$shape->getPlotArea()->getAxisX()->setTitle('');
$shape->getPlotArea()->getAxisY()->setTitle('');
When using adding charts to a PHPPresentation document it always needs repairing to open it. When repaired everything looks fine. If I don't include charts then the document opens without problems.
Not sure what I'm missing. Here's my function to add a chart:
function fnSlide_Bar(PhpPresentation $objPHPPresentation, $title, $audit_id, $query, $data = 'rows') { global $wpdb;
}