Skip to content

Bug: Setting fill color on line chart corrupts chart in XLSX writer. #589

@madrussa

Description

@madrussa

When setting the fill color property on a data series within a line chart and exporting it using the XLSX writer the chart becomes corrupt. The XLSX Chart writer has a bug on line:


It should not add the <c:spPr /> tag with colour properties here. It should add them to the <c:spPr /> tag generated for the line which occurs here:
https://github.com/PHPOffice/PhpSpreadsheet/blob/develop/src/PhpSpreadsheet/Writer/Xlsx/Chart.php#L1140

My workaround is to use a custom writer and I applied my fixes as below:
Line 1079:

$plotLabel = $plotGroup->getPlotLabelByIndex($plotSeriesIdx);
if ($plotLabel && $groupType !== DataSeries::TYPE_LINECHART &&
    $groupType !== DataSeries::TYPE_STOCKCHART
) {
    $fillColor = $plotLabel->getFillColor();
    if ($fillColor !== null) {
        $objWriter->startElement('c:spPr');
        $objWriter->startElement('a:solidFill');
        $objWriter->startElement('a:srgbClr');
        $objWriter->writeAttribute('val', $fillColor);
        $objWriter->endElement();
        $objWriter->endElement();
        $objWriter->endElement();
    }
}

Line 1143:

if ($groupType == DataSeries::TYPE_STOCKCHART) {
    $objWriter->startElement('a:noFill');
    $objWriter->endElement();
} elseif ($plotLabel && $plotLabel->getFillColor() !== null) {
    $objWriter->startElement('a:solidFill');
    $objWriter->startElement('a:srgbClr');
    $objWriter->writeAttribute('val', $plotLabel->getFillColor());
    $objWriter->endElement();
    $objWriter->endElement();
}

This probably isn't the best solution though as I don't know what impact it has on other chart types yet. I only know if affects line charts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions