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'])) {
57 public static function readChart(SimpleXMLElement $chartElements, $chartName)
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) {
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);
100 $XaxisLabel = $axisLabel;
105 $YaxisLabel = $axisLabel;
116 $plotSer->setPlotDirection($barDirection);
117 $plotSeries[] = $plotSer;
133 case 'doughnutChart':
136 $explosion = isset($chartDetail->ser->explosion);
138 $plotSer->setPlotStyle($explosion);
139 $plotSeries[] = $plotSer;
146 $plotSer->setPlotStyle($scatterStyle);
147 $plotSeries[] = $plotSer;
154 $plotSer->setPlotStyle($bubbleScale);
155 $plotSeries[] = $plotSer;
162 $plotSer->setPlotStyle($radarStyle);
163 $plotSeries[] = $plotSer;
168 case 'surface3DChart':
171 $plotSer->setPlotStyle($wireFrame);
172 $plotSeries[] = $plotSer;
183 if ($plotAreaLayout ==
null) {
184 $plotAreaLayout =
new Layout();
186 $plotArea =
new PlotArea($plotAreaLayout, $plotSeries);
204 $legendLayout =
null;
205 $legendOverlay =
false;
206 foreach ($chartDetails as $chartDetailKey => $chartDetail) {
207 switch ($chartDetailKey) {
222 $legend =
new Legend($legendPos, $legendLayout, $legendOverlay);
229 $chart = new \PhpOffice\PhpSpreadsheet\Chart\Chart($chartName,
$title,
$legend, $plotArea, $plotVisOnly, $dispBlanksAs, $XaxisLabel, $YaxisLabel);
234 private static function chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta)
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']);
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) {
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) {
294 foreach ($seriesDetails as $seriesKey => $seriesDetail) {
295 switch ($seriesKey) {
302 $plotOrder[$seriesIndex] = $seriesOrder;
338 return new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine);
343 if (isset($seriesDetail->strRef)) {
344 $seriesSource = (string) $seriesDetail->strRef->f;
347 if (isset($seriesDetail->strRef->strCache)) {
350 ->setFormatCode($seriesData[
'formatCode'])
351 ->setDataValues($seriesData[
'dataValues']);
354 return $seriesValues;
355 } elseif (isset($seriesDetail->numRef)) {
356 $seriesSource = (string) $seriesDetail->numRef->f;
358 if (isset($seriesDetail->numRef->numCache)) {
361 ->setFormatCode($seriesData[
'formatCode'])
362 ->setDataValues($seriesData[
'dataValues']);
365 return $seriesValues;
366 } elseif (isset($seriesDetail->multiLvlStrRef)) {
367 $seriesSource = (string) $seriesDetail->multiLvlStrRef->f;
370 if (isset($seriesDetail->multiLvlStrRef->multiLvlStrCache)) {
373 ->setFormatCode($seriesData[
'formatCode'])
374 ->setDataValues($seriesData[
'dataValues']);
377 return $seriesValues;
378 } elseif (isset($seriesDetail->multiLvlNumRef)) {
379 $seriesSource = (string) $seriesDetail->multiLvlNumRef->f;
382 if (isset($seriesDetail->multiLvlNumRef->multiLvlNumCache)) {
385 ->setFormatCode($seriesData[
'formatCode'])
386 ->setDataValues($seriesData[
'dataValues']);
389 return $seriesValues;
401 foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) {
402 switch ($seriesValueIdx) {
408 $formatCode = (string) $seriesValue;
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) {
446 $formatCode = (string) $seriesValue;
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']);
485 if ($fontSize !==
null) {
486 $objText->getFont()->setSize(floor($fontSize / 100));
490 if ($fontColor !==
null) {
491 $objText->getFont()->setColor(
new Color(self::readColor($fontColor)));
495 if ($bold !==
null) {
496 $objText->getFont()->setBold($bold);
500 if ($italic !==
null) {
501 $objText->getFont()->setItalic($italic);
505 if ($baseline !==
null) {
507 $objText->getFont()->setSuperscript(
true);
508 } elseif ($baseline < 0) {
509 $objText->getFont()->setSubscript(
true);
514 if ($underscore !==
null) {
515 if ($underscore ==
'sng') {
517 } elseif ($underscore ==
'dbl') {
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':
An exception for terminatinating execution or to throw for unit testing.
const DATASERIES_TYPE_NUMBER
const DATASERIES_TYPE_STRING
setShowLegendKey($value)
Set show legend key Specifies that legend keys should be shown in data labels.
setShowPercent($value)
Set show percentage Specifies that the percentage should be shown in data labels.
setShowBubbleSize($value)
Set show bubble size Specifies that the bubble size should be shown in data labels.
setShowCatName($value)
Set show cat name Specifies that the category name should be shown in data labels.
setShowSerName($value)
Set show ser name Specifies that the series name should be shown in data labels.
setShowVal($value)
Set show val Specifies that the value should be shown in data labels.
setShowLeaderLines($value)
Set show leader lines Specifies that leader lines should be shown in data labels.
static chartDataSeries($chartDetail, $namespacesChartMeta, $plotType)
static chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker=null)
static readChartAttributes($chartDetail)
static setChartAttributes(Layout $plotArea, $plotAttributes)
static getAttribute(SimpleXMLElement $component, $name, $format)
static chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta)
static chartDataSeriesValues($seriesValueSet, $dataType='n')
static readColor($color, $background=false)
static readChart(SimpleXMLElement $chartElements, $chartName)
static chartLayoutDetails($chartDetail, $namespacesChartMeta)
static chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType='n')
static parseRichText(SimpleXMLElement $titleDetailPart)
static indexedColor($pIndex, $background=false)
Get indexed color.
if(array_key_exists('yes', $_REQUEST)) $attributes