Added fillColor for chart plot series
For now it is only to write to Xlsx Closes #158
This commit is contained in:
parent
2761773b3d
commit
e6c95bf9b0
|
@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Support for chart fill color - @CrazyBite [#158](https://github.com/PHPOffice/PhpSpreadsheet/pull/158)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Merge data-validations to reduce written worksheet size - @billblume [#131](https://github.com/PHPOffice/PhpSpreadSheet/issues/131)
|
- Merge data-validations to reduce written worksheet size - @billblume [#131](https://github.com/PHPOffice/PhpSpreadSheet/issues/131)
|
||||||
|
|
|
@ -81,17 +81,26 @@ class DataSeriesValues
|
||||||
*/
|
*/
|
||||||
private $dataValues = [];
|
private $dataValues = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill color.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $fillColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new DataSeriesValues object.
|
* Create a new DataSeriesValues object.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* @param mixed $dataType
|
* @param mixed $dataType
|
||||||
* @param string $dataSource
|
* @param string $dataSource
|
||||||
* @param null|mixed $formatCode
|
* @param null|mixed $formatCode
|
||||||
* @param mixed $pointCount
|
* @param mixed $pointCount
|
||||||
* @param mixed $dataValues
|
* @param mixed $dataValues
|
||||||
* @param null|mixed $marker
|
* @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->setDataType($dataType);
|
||||||
$this->dataSource = $dataSource;
|
$this->dataSource = $dataSource;
|
||||||
|
@ -99,6 +108,7 @@ class DataSeriesValues
|
||||||
$this->pointCount = $pointCount;
|
$this->pointCount = $pointCount;
|
||||||
$this->dataValues = $dataValues;
|
$this->dataValues = $dataValues;
|
||||||
$this->pointMarker = $marker;
|
$this->pointMarker = $marker;
|
||||||
|
$this->fillColor = $fillColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,6 +227,33 @@ class DataSeriesValues
|
||||||
return $this->pointCount;
|
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.
|
* Identify if the Data Series is a multi-level or a simple series.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1098,6 +1098,20 @@ class Chart extends WriterPart
|
||||||
foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
|
foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
|
||||||
$objWriter->startElement('c:ser');
|
$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->startElement('c:idx');
|
||||||
$objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx);
|
$objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
Loading…
Reference in New Issue