Added fillColor for chart plot series

For now it is only to write to Xlsx

Closes #158
This commit is contained in:
CrazyBite 2017-05-03 15:53:07 +03:00 committed by Adrien Crivelli
parent 2761773b3d
commit e6c95bf9b0
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 54 additions and 1 deletions

View File

@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Support for chart fill color - @CrazyBite [#158](https://github.com/PHPOffice/PhpSpreadsheet/pull/158)
### Changed
- Merge data-validations to reduce written worksheet size - @billblume [#131](https://github.com/PHPOffice/PhpSpreadSheet/issues/131)

View File

@ -81,17 +81,26 @@ class DataSeriesValues
*/
private $dataValues = [];
/**
* Fill color.
*
* @var string
*/
private $fillColor;
/**
* Create a new DataSeriesValues object.
*
*
* @param mixed $dataType
* @param string $dataSource
* @param null|mixed $formatCode
* @param mixed $pointCount
* @param mixed $dataValues
* @param null|mixed $marker
* @param null|string $fillColor
*/
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, $fillColor = null)
{
$this->setDataType($dataType);
$this->dataSource = $dataSource;
@ -99,6 +108,7 @@ class DataSeriesValues
$this->pointCount = $pointCount;
$this->dataValues = $dataValues;
$this->pointMarker = $marker;
$this->fillColor = $fillColor;
}
/**
@ -217,6 +227,33 @@ class DataSeriesValues
return $this->pointCount;
}
/**
* Get fill color.
*
* @return string HEX color
*/
public function getFillColor()
{
return $this->fillColor;
}
/**
* Set fill color for series.
*
* @param string $color HEX 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.
*

View File

@ -1098,6 +1098,20 @@ class Chart extends WriterPart
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();