diff --git a/src/PhpSpreadsheet/Chart/DataSeriesValues.php b/src/PhpSpreadsheet/Chart/DataSeriesValues.php index 82813400aa..a98ed669ce 100644 --- a/src/PhpSpreadsheet/Chart/DataSeriesValues.php +++ b/src/PhpSpreadsheet/Chart/DataSeriesValues.php @@ -80,13 +80,24 @@ class DataSeriesValues * Create a new DataSeriesValues object. * * @param mixed $dataType + * Fill color. + * + * @var string + */ + private $fillColor; + + /** + * Create a new DataSeriesValues object. + * * @param string $dataSource * @param null|mixed $formatCode * @param mixed $pointCount * @param mixed $dataValues * @param null|mixed $marker + * @param mixed $dataType + * @param null|mixed $color */ - public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSource = null, $formatCode = null, $pointCount = 0, $dataValues = [], $marker = null) + public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSource = null, $formatCode = null, $pointCount = 0, $dataValues = [], $marker = null, $color = null) { $this->setDataType($dataType); $this->dataSource = $dataSource; @@ -94,6 +105,7 @@ public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSourc $this->pointCount = $pointCount; $this->dataValues = $dataValues; $this->pointMarker = $marker; + $this->fillColor = $color; } /** @@ -212,6 +224,35 @@ public function getPointCount() return $this->pointCount; } + /** + * Identify if the Data Series is a multi-level or a simple series. + * Get fill color. + * + * @return string + */ + public function getFillColor() + { + return $this->fillColor; + } + + /** + * Set fill color for series. + * + * @param string HEX color + * @param mixed $color + * + * @return DataSeriesValues + */ + public function setFillColor($color) + { + if (!preg_match('/^[a-f0-9]{6}$/i', $color)) { + throw new Exception('Invalid hex color for chart series'); + } + $this->fillColor = $color; + + return $this; + } + /** * Identify if the Data Series is a multi-level or a simple series. * diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php index 418688f7b9..8815d130cc 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -1095,6 +1095,19 @@ private function writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMulti foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) { $objWriter->startElement('c:ser'); + $plotLabel = $plotGroup->getPlotLabelByIndex($plotSeriesIdx); + if ($plotLabel){ + $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(); + } + } $objWriter->startElement('c:idx'); $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx); $objWriter->endElement();