31 } elseif (
$format ==
'integer') {
33 } elseif (
$format ==
'boolean') {
43 private static function readColor($color, $background =
false)
45 if (isset($color[
'rgb'])) {
46 return (
string) $color[
'rgb'];
47 } elseif (isset($color[
'indexed'])) {
59 $namespacesChartMeta = $chartElements->getNamespaces(
true);
60 $chartElementsC = $chartElements->children($namespacesChartMeta[
'c']);
63 $dispBlanksAs = $plotVisOnly = null;
65 foreach ($chartElementsC as $chartElementKey => $chartElement) {
66 switch ($chartElementKey) {
68 foreach ($chartElement as $chartDetailsKey => $chartDetails) {
69 $chartDetailsC = $chartDetails->children($namespacesChartMeta[
'c']);
70 switch ($chartDetailsKey) {
72 $plotAreaLayout = $XaxisLable = $YaxisLable = null;
73 $plotSeries = $plotAttributes = [];
74 foreach ($chartDetails as $chartDetailKey => $chartDetail) {
75 switch ($chartDetailKey) {
77 $plotAreaLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);
81 if (isset($chartDetail->title)) {
82 $XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta[
'c']), $namespacesChartMeta);
87 if (isset($chartDetail->title)) {
88 $XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta[
'c']), $namespacesChartMeta);
93 if (isset($chartDetail->title, $chartDetail->axPos)) {
94 $axisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta[
'c']), $namespacesChartMeta);
95 $axPos = self::getAttribute($chartDetail->axPos,
'val',
'string');
100 $XaxisLabel = $axisLabel;
105 $YaxisLabel = $axisLabel;
114 $barDirection = self::getAttribute($chartDetail->barDir,
'val',
'string');
115 $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
116 $plotSer->setPlotDirection($barDirection);
117 $plotSeries[] = $plotSer;
118 $plotAttributes = self::readChartAttributes($chartDetail);
123 $plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
124 $plotAttributes = self::readChartAttributes($chartDetail);
129 $plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
130 $plotAttributes = self::readChartAttributes($chartDetail);
133 case 'doughnutChart':
136 $explosion = isset($chartDetail->ser->explosion);
137 $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
138 $plotSer->setPlotStyle($explosion);
139 $plotSeries[] = $plotSer;
140 $plotAttributes = self::readChartAttributes($chartDetail);
144 $scatterStyle = self::getAttribute($chartDetail->scatterStyle,
'val',
'string');
145 $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
146 $plotSer->setPlotStyle($scatterStyle);
147 $plotSeries[] = $plotSer;
148 $plotAttributes = self::readChartAttributes($chartDetail);
152 $bubbleScale = self::getAttribute($chartDetail->bubbleScale,
'val',
'integer');
153 $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
154 $plotSer->setPlotStyle($bubbleScale);
155 $plotSeries[] = $plotSer;
156 $plotAttributes = self::readChartAttributes($chartDetail);
160 $radarStyle = self::getAttribute($chartDetail->radarStyle,
'val',
'string');
161 $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
162 $plotSer->setPlotStyle($radarStyle);
163 $plotSeries[] = $plotSer;
164 $plotAttributes = self::readChartAttributes($chartDetail);
168 case 'surface3DChart':
169 $wireFrame = self::getAttribute($chartDetail->wireframe,
'val',
'boolean');
170 $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
171 $plotSer->setPlotStyle($wireFrame);
172 $plotSeries[] = $plotSer;
173 $plotAttributes = self::readChartAttributes($chartDetail);
177 $plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
178 $plotAttributes = self::readChartAttributes($plotAreaLayout);
183 if ($plotAreaLayout == null) {
184 $plotAreaLayout =
new Layout();
186 $plotArea =
new PlotArea($plotAreaLayout, $plotSeries);
187 self::setChartAttributes($plotAreaLayout, $plotAttributes);
191 $plotVisOnly = self::getAttribute($chartDetails,
'val',
'string');
195 $dispBlanksAs = self::getAttribute($chartDetails,
'val',
'string');
199 $title = self::chartTitle($chartDetails, $namespacesChartMeta);
204 $legendLayout = null;
205 $legendOverlay =
false;
206 foreach ($chartDetails as $chartDetailKey => $chartDetail) {
207 switch ($chartDetailKey) {
209 $legendPos = self::getAttribute($chartDetail,
'val',
'string');
213 $legendOverlay = self::getAttribute($chartDetail,
'val',
'boolean');
217 $legendLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);
222 $legend =
new Legend($legendPos, $legendLayout, $legendOverlay);
229 $chart = new \PhpOffice\PhpSpreadsheet\Chart\Chart($chartName,
$title,
$legend, $plotArea, $plotVisOnly, $dispBlanksAs, $XaxisLabel, $YaxisLabel);
238 foreach ($titleDetails as $titleDetailKey => $chartDetail) {
239 switch ($titleDetailKey) {
241 $titleDetails = $chartDetail->rich->children($namespacesChartMeta[
'a']);
242 foreach ($titleDetails as $titleKey => $titleDetail) {
245 $titleDetailPart = $titleDetail->children($namespacesChartMeta[
'a']);
246 $caption[] = self::parseRichText($titleDetailPart);
252 $titleLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);
258 return new Title($caption, $titleLayout);
263 if (!isset($chartDetail->manualLayout)) {
266 $details = $chartDetail->manualLayout->children($namespacesChartMeta[
'c']);
267 if ($details === null) {
271 foreach ($details as $detailKey => $detail) {
272 $layout[$detailKey] = self::getAttribute($detail,
'val',
'string');
275 return new Layout($layout);
278 private static function chartDataSeries($chartDetail, $namespacesChartMeta, $plotType)
280 $multiSeriesType = null;
282 $seriesLabel = $seriesCategory = $seriesValues = $plotOrder = [];
284 $seriesDetailSet = $chartDetail->children($namespacesChartMeta[
'c']);
285 foreach ($seriesDetailSet as $seriesDetailKey => $seriesDetails) {
286 switch ($seriesDetailKey) {
288 $multiSeriesType = self::getAttribute($chartDetail->grouping,
'val',
'string');
294 foreach ($seriesDetails as $seriesKey => $seriesDetail) {
295 switch ($seriesKey) {
297 $seriesIndex = self::getAttribute($seriesDetail,
'val',
'integer');
301 $seriesOrder = self::getAttribute($seriesDetail,
'val',
'integer');
302 $plotOrder[$seriesIndex] = $seriesOrder;
306 $seriesLabel[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta);
310 $marker = self::getAttribute($seriesDetail->symbol,
'val',
'string');
314 $smoothLine = self::getAttribute($seriesDetail,
'val',
'boolean');
318 $seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta);
322 $seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker);
326 $seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker);
330 $seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker);
338 return new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine);
343 if (isset($seriesDetail->strRef)) {
344 $seriesSource = (string) $seriesDetail->strRef->f;
345 $seriesValues =
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, null, null, null, $marker);
347 if (isset($seriesDetail->strRef->strCache)) {
348 $seriesData = self::chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta[
'c']),
's');
351 ->setDataValues($seriesData[
'dataValues']);
354 return $seriesValues;
355 } elseif (isset($seriesDetail->numRef)) {
356 $seriesSource = (string) $seriesDetail->numRef->f;
357 $seriesValues =
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $seriesSource, null, null, null, $marker);
358 if (isset($seriesDetail->numRef->numCache)) {
359 $seriesData = self::chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta[
'c']));
362 ->setDataValues($seriesData[
'dataValues']);
365 return $seriesValues;
366 } elseif (isset($seriesDetail->multiLvlStrRef)) {
367 $seriesSource = (string) $seriesDetail->multiLvlStrRef->f;
368 $seriesValues =
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, null, null, null, $marker);
370 if (isset($seriesDetail->multiLvlStrRef->multiLvlStrCache)) {
371 $seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta[
'c']),
's');
374 ->setDataValues($seriesData[
'dataValues']);
377 return $seriesValues;
378 } elseif (isset($seriesDetail->multiLvlNumRef)) {
379 $seriesSource = (string) $seriesDetail->multiLvlNumRef->f;
380 $seriesValues =
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, null, null, null, $marker);
382 if (isset($seriesDetail->multiLvlNumRef->multiLvlNumCache)) {
383 $seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta[
'c']),
's');
386 ->setDataValues($seriesData[
'dataValues']);
389 return $seriesValues;
401 foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) {
402 switch ($seriesValueIdx) {
404 $pointCount = self::getAttribute($seriesValue,
'val',
'integer');
408 $formatCode = (string) $seriesValue;
412 $pointVal = self::getAttribute($seriesValue,
'idx',
'integer');
413 if ($dataType ==
's') {
414 $seriesVal[$pointVal] = (string) $seriesValue->v;
416 $seriesVal[$pointVal] = null;
418 $seriesVal[$pointVal] = (float) $seriesValue->v;
426 'formatCode' => $formatCode,
427 'pointCount' => $pointCount,
428 'dataValues' => $seriesVal,
438 foreach ($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) {
439 foreach ($seriesLevel as $seriesValueIdx => $seriesValue) {
440 switch ($seriesValueIdx) {
442 $pointCount = self::getAttribute($seriesValue,
'val',
'integer');
446 $formatCode = (string) $seriesValue;
450 $pointVal = self::getAttribute($seriesValue,
'idx',
'integer');
451 if ($dataType ==
's') {
452 $seriesVal[$pointVal][] = (string) $seriesValue->v;
454 $seriesVal[$pointVal] = null;
456 $seriesVal[$pointVal][] = (float) $seriesValue->v;
465 'formatCode' => $formatCode,
466 'pointCount' => $pointCount,
467 'dataValues' => $seriesVal,
475 foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) {
476 if (isset($titleDetailElement->t)) {
477 $objText = $value->createTextRun((
string) $titleDetailElement->t);
479 if (isset($titleDetailElement->rPr)) {
480 if (isset($titleDetailElement->rPr->rFont[
'val'])) {
481 $objText->getFont()->setName((
string) $titleDetailElement->rPr->rFont[
'val']);
484 $fontSize = (self::getAttribute($titleDetailElement->rPr,
'sz',
'integer'));
485 if ($fontSize !== null) {
486 $objText->getFont()->setSize(floor($fontSize / 100));
489 $fontColor = (self::getAttribute($titleDetailElement->rPr,
'color',
'string'));
490 if ($fontColor !== null) {
491 $objText->getFont()->setColor(
new Color(self::readColor($fontColor)));
494 $bold = self::getAttribute($titleDetailElement->rPr,
'b',
'boolean');
495 if ($bold !== null) {
496 $objText->getFont()->setBold($bold);
499 $italic = self::getAttribute($titleDetailElement->rPr,
'i',
'boolean');
500 if ($italic !== null) {
501 $objText->getFont()->setItalic($italic);
504 $baseline = self::getAttribute($titleDetailElement->rPr,
'baseline',
'integer');
505 if ($baseline !== null) {
507 $objText->getFont()->setSuperscript(
true);
508 } elseif ($baseline < 0) {
509 $objText->getFont()->setSubscript(
true);
513 $underscore = (self::getAttribute($titleDetailElement->rPr,
'u',
'string'));
514 if ($underscore !== null) {
515 if ($underscore ==
'sng') {
516 $objText->getFont()->setUnderline(Font::UNDERLINE_SINGLE);
517 } elseif ($underscore ==
'dbl') {
518 $objText->getFont()->setUnderline(Font::UNDERLINE_DOUBLE);
520 $objText->getFont()->setUnderline(Font::UNDERLINE_NONE);
524 $strikethrough = (self::getAttribute($titleDetailElement->rPr,
's',
'string'));
525 if ($strikethrough !== null) {
526 if ($strikethrough ==
'noStrike') {
527 $objText->getFont()->setStrikethrough(
false);
529 $objText->getFont()->setStrikethrough(
true);
540 $plotAttributes = [];
541 if (isset($chartDetail->dLbls)) {
542 if (isset($chartDetail->dLbls->showLegendKey)) {
543 $plotAttributes[
'showLegendKey'] = self::getAttribute($chartDetail->dLbls->showLegendKey,
'val',
'string');
545 if (isset($chartDetail->dLbls->showVal)) {
546 $plotAttributes[
'showVal'] = self::getAttribute($chartDetail->dLbls->showVal,
'val',
'string');
548 if (isset($chartDetail->dLbls->showCatName)) {
549 $plotAttributes[
'showCatName'] = self::getAttribute($chartDetail->dLbls->showCatName,
'val',
'string');
551 if (isset($chartDetail->dLbls->showSerName)) {
552 $plotAttributes[
'showSerName'] = self::getAttribute($chartDetail->dLbls->showSerName,
'val',
'string');
554 if (isset($chartDetail->dLbls->showPercent)) {
555 $plotAttributes[
'showPercent'] = self::getAttribute($chartDetail->dLbls->showPercent,
'val',
'string');
557 if (isset($chartDetail->dLbls->showBubbleSize)) {
558 $plotAttributes[
'showBubbleSize'] = self::getAttribute($chartDetail->dLbls->showBubbleSize,
'val',
'string');
560 if (isset($chartDetail->dLbls->showLeaderLines)) {
561 $plotAttributes[
'showLeaderLines'] = self::getAttribute($chartDetail->dLbls->showLeaderLines,
'val',
'string');
565 return $plotAttributes;
573 foreach ($plotAttributes as $plotAttributeKey => $plotAttributeValue) {
574 switch ($plotAttributeKey) {
575 case 'showLegendKey':
595 case 'showBubbleSize':
599 case 'showLeaderLines':
setShowBubbleSize($value)
Set show bubble size Specifies that the bubble size should be shown in data labels.
static parseRichText(SimpleXMLElement $titleDetailPart)
static getAttribute(SimpleXMLElement $component, $name, $format)
setShowPercent($value)
Set show percentage Specifies that the percentage should be shown in data labels. ...
setFormatCode($formatCode)
Set Series Format Code.
static chartDataSeriesValues($seriesValueSet, $dataType='n')
static chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker=null)
static chartDataSeries($chartDetail, $namespacesChartMeta, $plotType)
static readChart(SimpleXMLElement $chartElements, $chartName)
static readChartAttributes($chartDetail)
static chartLayoutDetails($chartDetail, $namespacesChartMeta)
setShowLeaderLines($value)
Set show leader lines Specifies that leader lines should be shown in data labels. ...
static indexedColor($pIndex, $background=false)
Get indexed color.
setShowSerName($value)
Set show ser name Specifies that the series name should be shown in data labels.
static chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta)
if(array_key_exists('yes', $_REQUEST)) $attributes
static chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType='n')
setShowVal($value)
Set show val Specifies that the value should be shown in data labels.
static readColor($color, $background=false)
static setChartAttributes(Layout $plotArea, $plotAttributes)
setShowLegendKey($value)
Set show legend key Specifies that legend keys should be shown in data labels.
setShowCatName($value)
Set show cat name Specifies that the category name should be shown in data labels.