PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Writer\Exception
Chart is not yet implemented
Error message
Chart is not yet implemented
What it means
When writing charts to Xlsx, the chart writer derives the chart-type list from the plot area: either the single plot group's type, or the unique types of all plot groups. If that list ends up empty - no DataSeries attached to the PlotArea, or every series having a null plot type - it throws this generic 'not yet implemented' message. It fires at save() time, after the chart was already added to a worksheet (and only when the writer includes charts).
Source
Thrown at src/PhpSpreadsheet/Writer/Xlsx/Chart.php:1115
private static function getChartType(PlotArea $plotArea): array
{
$groupCount = $plotArea->getPlotGroupCount();
if ($groupCount == 1) {
$plotType = $plotArea->getPlotGroupByIndex(0)->getPlotType();
$chartType = ($plotType === null) ? [] : [$plotType];
} else {
$chartTypes = [];
for ($i = 0; $i < $groupCount; ++$i) {
$plotType = $plotArea->getPlotGroupByIndex($i)->getPlotType();
if ($plotType !== null) {
$chartTypes[] = $plotType;
}
}
$chartType = array_unique($chartTypes);
}
if (count($chartType) == 0) {
throw new WriterException('Chart is not yet implemented');
}
return $chartType;
}
/**
* Method writing plot series values.
*/
private function writePlotSeriesValuesElement(XMLWriter $objWriter, int $val, ?ChartColor $fillColor): void
{
if ($fillColor === null || !$fillColor->isUsable()) {
return;
}
$objWriter->startElement('c:dPt');
$objWriter->startElement('c:idx');
$objWriter->writeAttribute('val', "$val");
$objWriter->endElement(); // c:idxView on GitHub (pinned to 65b080eef4)
Solutions
- Attach at least one DataSeries with an explicit plot type (e.g. DataSeries::TYPE_PIECHART) to the PlotArea before addChart()
- Skip creating/adding the chart entirely when it would have no series
- Guard data-driven charts: only addChart() when the series values are non-empty
Example fix
// before
$chart = new Chart('chart1');
$chart->setPlotArea(new PlotArea(null, []));
$sheet->addChart($chart);
// after
$values = new DataSeriesValues('Number', 'Data!$B$2:$B$5', null, 4);
$series = new DataSeries(DataSeries::TYPE_PIECHART, null, [0], [null], [null], [$values]);
$chart = new Chart('chart1', new Title('Chart'), null, new PlotArea(null, [$series]));
$sheet->addChart($chart); Defensive patterns
Strategy: validation
Validate before calling
/** Ensure every chart has at least one typed plot group before saving Xlsx. */
function chartsAreWritable(Spreadsheet $spreadsheet): bool
{
foreach ($spreadsheet->getAllSheets() as $sheet) {
foreach ($sheet->getChartCollection() as $chart) {
$groups = $chart->getPlotArea()?->getPlotGroup() ?? [];
$typed = array_filter($groups, fn ($g) => $g->getPlotType() !== null);
if (count($typed) === 0) {
return false;
}
}
}
return true;
}
if (!chartsAreWritable($spreadsheet)) {
// drop empty charts instead of failing the whole export
foreach ($spreadsheet->getAllSheets() as $sheet) {
// remove chart-less series charts per your model
}
}
$writer->setIncludeCharts(true);
$writer->save('out.xlsx'); Try / catch
try {
$writer->setIncludeCharts(true);
$writer->save('out.xlsx');
} catch (\PhpOffice\PhpSpreadsheet\Writer\Exception $e) {
if (str_contains($e->getMessage(), 'Chart is not yet implemented')) {
$writer->setIncludeCharts(false);
$writer->save('out-nocharts.xlsx'); // deliver data now, fix charts later
} else {
throw $e;
}
} Prevention
- Never addChart() without verifying the PlotArea holds a DataSeries with a non-null plot type
- Build charts in one factory method that always constructs label/category/values DataSeriesValues together
- Cover chart construction with a test that round-trips every generated chart through the Xlsx writer
When it happens
Trigger: $chart = new Chart('chart'); $chart->setPlotArea(new PlotArea(null, [])); $sheet->addChart($chart); then ->save('out.xlsx') - zero plot groups yields an empty type list; also attaching only DataSeries objects whose plot type is null.
Common situations: Programmatically built charts where attaching the DataSeries was forgotten; charts whose series values come from a query that returned no data; editing a loaded chart and dropping its plot groups.
Related errors
- Workbook already contains a table named '{$this->name}'
- Sheet does not have a chart named $chartName.
- Directory does not exist: $cacheDirectory
- Could not open file "{$filename}" for writing.
- Could not close file after writing.
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/0a7a30431be9c3f1.
Report an issue: GitHub.