46 private static $_colourSet =
array(
'mediumpurple1',
'palegreen3',
'gold1',
'cadetblue1',
47 'darkmagenta',
'coral',
'dodgerblue3',
'eggplant',
48 'mediumblue',
'magenta',
'sandybrown',
'cyan',
49 'firebrick1',
'forestgreen',
'deeppink4',
'darkolivegreen',
54 'square' => MARK_SQUARE,
55 'triangle' => MARK_UTRIANGLE,
58 'dot' => MARK_FILLEDCIRCLE,
59 'dash' => MARK_DTRIANGLE,
60 'circle' => MARK_CIRCLE,
75 $plotMarkKeys = array_keys(self::$_markSet);
76 if (is_null($markerID)) {
78 self::$_plotMark %= count(self::$_markSet);
79 $seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
80 } elseif ($markerID !==
'none') {
82 if (isset(self::$_markSet[$markerID])) {
83 $seriesPlot->mark->SetType(self::$_markSet[$markerID]);
86 self::$_plotMark %= count(self::$_markSet);
87 $seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
91 $seriesPlot->mark->Hide();
93 $seriesPlot->mark->SetColor(self::$_colourSet[self::$_plotColour]);
94 $seriesPlot->mark->SetFillColor(self::$_colourSet[self::$_plotColour]);
95 $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
102 $datasetLabelFormatCode = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
103 if (!is_null($datasetLabelFormatCode)) {
105 $datasetLabelFormatCode = stripslashes($datasetLabelFormatCode);
108 $testCurrentIndex = 0;
109 foreach($datasetLabels as
$i => $datasetLabel) {
110 if (is_array($datasetLabel)) {
111 if ($rotation ==
'bar') {
112 $datasetLabels[
$i] = implode(
" ",$datasetLabel);
114 $datasetLabel = array_reverse($datasetLabel);
115 $datasetLabels[
$i] = implode(
"\n",$datasetLabel);
119 if (!is_null($datasetLabelFormatCode)) {
126 return $datasetLabels;
132 for(
$i = 0;
$i < $seriesCount; ++
$i) {
134 $sumValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getDataValues();
136 $nextValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getDataValues();
137 foreach($nextValues as $k => $value) {
138 if (isset($sumValues[$k])) {
139 $sumValues[$k] += $value;
141 $sumValues[$k] = $value;
152 foreach($dataValues as $k => $dataValue) {
153 $dataValues[$k] = $dataValue / $sumValues[$k] * 100;
162 $caption = (!is_null($captionElement)) ? $captionElement->getCaption() : NULL;
164 if (!is_null($caption)) {
166 if (is_array($caption)) {
168 $caption = implode(
'',$caption);
178 $this->_graph->title->Set(
$title);
184 $legend = $this->_chart->getLegend();
186 $legendPosition =
$legend->getPosition();
187 $legendOverlay =
$legend->getOverlay();
188 switch ($legendPosition) {
190 $this->_graph->legend->SetPos(0.01,0.5,
'right',
'center');
191 $this->_graph->legend->SetColumns(1);
194 $this->_graph->legend->SetPos(0.01,0.5,
'left',
'center');
195 $this->_graph->legend->SetColumns(1);
198 $this->_graph->legend->SetPos(0.5,0.01,
'center',
'top');
201 $this->_graph->legend->SetPos(0.5,0.99,
'center',
'bottom');
204 $this->_graph->legend->SetPos(0.01,0.01,
'right',
'top');
205 $this->_graph->legend->SetColumns(1);
209 $this->_graph->legend->Hide();
215 $this->_graph =
new Graph(self::$_width,self::$_height);
216 $this->_graph->SetScale(
$type);
221 $rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotDirection();
222 $reverse = ($rotation ==
'bar') ?
true :
false;
228 $this->_graph->xaxis->SetTitle(
$title,
'center');
229 $this->_graph->xaxis->title->SetMargin(35);
231 $this->_graph->xaxis->title->SetAngle(90);
232 $this->_graph->xaxis->title->SetMargin(90);
241 $this->_graph->yaxis->SetTitle(
$title,
'center');
243 $this->_graph->yaxis->title->SetAngle(0);
244 $this->_graph->yaxis->title->SetMargin(-55);
252 $this->_graph =
new PieGraph(self::$_width,self::$_height);
259 $this->_graph =
new RadarGraph(self::$_width,self::$_height);
260 $this->_graph->SetScale(
'lin');
266 private function _renderPlotLine($groupID, $filled =
false, $combination =
false, $dimensions =
'2d') {
267 $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
269 $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
270 if ($labelCount > 0) {
271 $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
273 $this->_graph->xaxis->SetTickLabels($datasetLabels);
276 $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
277 $seriesPlots =
array();
278 if ($grouping ==
'percentStacked') {
283 for(
$i = 0;
$i < $seriesCount; ++
$i) {
284 $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getDataValues();
285 $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getPointMarker();
287 if ($grouping ==
'percentStacked') {
292 $testCurrentIndex = 0;
293 foreach($dataValues as $k => $dataValue) {
294 while($k != $testCurrentIndex) {
295 $dataValues[$testCurrentIndex] = null;
301 $seriesPlot =
new LinePlot($dataValues);
303 $seriesPlot->SetBarCenter();
307 $seriesPlot->SetFilled(
true);
308 $seriesPlot->SetColor(
'black');
309 $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
314 $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex(
$i)->getDataValue();
315 $seriesPlot->SetLegend($dataLabel);
317 $seriesPlots[] = $seriesPlot;
320 if ($grouping ==
'standard') {
321 $groupPlot = $seriesPlots;
323 $groupPlot =
new AccLinePlot($seriesPlots);
325 $this->_graph->Add($groupPlot);
330 $rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotDirection();
332 if (($groupID == 0) && ($rotation ==
'bar')) {
333 $this->_graph->Set90AndMargin();
335 $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
337 $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
338 if ($labelCount > 0) {
339 $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
342 if ($rotation ==
'bar') {
343 $datasetLabels = array_reverse($datasetLabels);
344 $this->_graph->yaxis->SetPos(
'max');
345 $this->_graph->yaxis->SetLabelAlign(
'center',
'top');
346 $this->_graph->yaxis->SetLabelSide(SIDE_RIGHT);
348 $this->_graph->xaxis->SetTickLabels($datasetLabels);
352 $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
353 $seriesPlots =
array();
354 if ($grouping ==
'percentStacked') {
359 for($j = 0; $j < $seriesCount; ++$j) {
360 $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
361 if ($grouping ==
'percentStacked') {
366 $testCurrentIndex = 0;
367 foreach($dataValues as $k => $dataValue) {
368 while($k != $testCurrentIndex) {
369 $dataValues[$testCurrentIndex] = null;
376 if ($rotation ==
'bar') {
377 $dataValues = array_reverse($dataValues);
379 $seriesPlot =
new BarPlot($dataValues);
380 $seriesPlot->SetColor(
'black');
381 $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
382 if ($dimensions ==
'3d') {
383 $seriesPlot->SetShadow();
385 if (!$this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) {
388 $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue();
390 $seriesPlot->SetLegend($dataLabel);
392 $seriesPlots[] = $seriesPlot;
395 if (($rotation ==
'bar') && (!($grouping ==
'percentStacked'))) {
396 $seriesPlots = array_reverse($seriesPlots);
399 if ($grouping ==
'clustered') {
400 $groupPlot =
new GroupBarPlot($seriesPlots);
401 } elseif ($grouping ==
'standard') {
402 $groupPlot =
new GroupBarPlot($seriesPlots);
404 $groupPlot =
new AccBarPlot($seriesPlots);
405 if ($dimensions ==
'3d') {
406 $groupPlot->SetShadow();
410 $this->_graph->Add($groupPlot);
415 $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
416 $scatterStyle = $bubbleSize = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
418 $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
419 $seriesPlots =
array();
422 for(
$i = 0;
$i < $seriesCount; ++
$i) {
423 $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(
$i)->getDataValues();
424 $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getDataValues();
426 foreach($dataValuesY as $k => $dataValueY) {
427 $dataValuesY[$k] = $k;
430 $seriesPlot =
new ScatterPlot($dataValuesX,$dataValuesY);
431 if ($scatterStyle ==
'lineMarker') {
432 $seriesPlot->SetLinkPoints();
433 $seriesPlot->link->SetColor(self::$_colourSet[self::$_plotColour]);
434 } elseif ($scatterStyle ==
'smoothMarker') {
435 $spline =
new Spline($dataValuesY,$dataValuesX);
436 list($splineDataY,$splineDataX) = $spline->Get(count($dataValuesX) * self::$_width / 20);
437 $lplot =
new LinePlot($splineDataX,$splineDataY);
438 $lplot->SetColor(self::$_colourSet[self::$_plotColour]);
440 $this->_graph->Add($lplot);
445 $seriesPlot->mark->SetColor(
'black');
446 $seriesPlot->mark->SetSize($bubbleSize);
448 $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getPointMarker();
451 $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex(
$i)->getDataValue();
452 $seriesPlot->SetLegend($dataLabel);
454 $this->_graph->Add($seriesPlot);
460 $radarStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
462 $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
463 $seriesPlots =
array();
466 for(
$i = 0;
$i < $seriesCount; ++
$i) {
467 $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(
$i)->getDataValues();
468 $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getDataValues();
469 $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getPointMarker();
471 $dataValues =
array();
472 foreach($dataValuesY as $k => $dataValueY) {
473 $dataValues[$k] = implode(
' ',array_reverse($dataValueY));
475 $tmp = array_shift($dataValues);
476 $dataValues[] = $tmp;
477 $tmp = array_shift($dataValuesX);
478 $dataValuesX[] = $tmp;
480 $this->_graph->SetTitles(array_reverse($dataValues));
482 $seriesPlot =
new RadarPlot(array_reverse($dataValuesX));
484 $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex(
$i)->getDataValue();
485 $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
486 if ($radarStyle ==
'filled') {
487 $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour]);
490 $seriesPlot->SetLegend($dataLabel);
492 $this->_graph->Add($seriesPlot);
498 $contourStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
500 $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
501 $seriesPlots =
array();
503 $dataValues =
array();
505 for(
$i = 0;
$i < $seriesCount; ++
$i) {
506 $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(
$i)->getDataValues();
507 $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(
$i)->getDataValues();
509 $dataValues[
$i] = $dataValuesX;
511 $seriesPlot =
new ContourPlot($dataValues);
513 $this->_graph->Add($seriesPlot);
518 $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
519 $plotOrder = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder();
521 $dataValues =
array();
523 foreach($plotOrder as
$i => $v) {
524 $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($v)->getDataValues();
525 foreach($dataValuesX as $j => $dataValueX) {
526 $dataValues[$plotOrder[
$i]][$j] = $dataValueX;
529 if(empty($dataValues)) {
533 $dataValuesPlot =
array();
535 for($j = 0; $j < count($dataValues[0]); $j++) {
536 for(
$i = 0;
$i < $seriesCount;
$i++) {
537 $dataValuesPlot[] = $dataValues[
$i][$j];
542 $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
543 if ($labelCount > 0) {
544 $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
546 $this->_graph->xaxis->SetTickLabels($datasetLabels);
549 $seriesPlot =
new StockPlot($dataValuesPlot);
550 $seriesPlot->SetWidth(20);
552 $this->_graph->Add($seriesPlot);
561 for(
$i = 0;
$i < $groupCount; ++
$i) {
572 for(
$i = 0;
$i < $groupCount; ++
$i) {
583 for(
$i = 0;
$i < $groupCount; ++
$i) {
596 for(
$i = 0;
$i < $groupCount; ++
$i) {
607 for(
$i = 0;
$i < $groupCount; ++
$i) {
613 private function _renderPieChart($groupCount, $dimensions =
'2d', $doughnut = False, $multiplePlots = False) {
615 if ($dimensions ==
'3d') {
621 $iLimit = ($multiplePlots) ? $groupCount : 1;
622 for($groupID = 0; $groupID < $iLimit; ++$groupID) {
623 $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
624 $exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
626 $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
627 if ($labelCount > 0) {
628 $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
633 $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
634 $seriesPlots =
array();
636 $jLimit = ($multiplePlots) ? $seriesCount : 1;
638 for($j = 0; $j < $jLimit; ++$j) {
639 $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
642 $testCurrentIndex = 0;
643 foreach($dataValues as $k => $dataValue) {
644 while($k != $testCurrentIndex) {
645 $dataValues[$testCurrentIndex] = null;
651 if ($dimensions ==
'3d') {
652 $seriesPlot =
new PiePlot3D($dataValues);
655 $seriesPlot =
new PiePlotC($dataValues);
657 $seriesPlot =
new PiePlot($dataValues);
661 if ($multiplePlots) {
662 $seriesPlot->SetSize(($jLimit-$j) / ($jLimit * 4));
666 $seriesPlot->SetMidColor(
'white');
669 $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
670 if (count($datasetLabels) > 0)
671 $seriesPlot->SetLabels(array_fill(0,count($datasetLabels),
''));
672 if ($dimensions !=
'3d') {
673 $seriesPlot->SetGuideLines(
false);
677 $seriesPlot->ExplodeAll();
679 $seriesPlot->SetLegends($datasetLabels);
682 $this->_graph->Add($seriesPlot);
693 for($groupID = 0; $groupID < $groupCount; ++$groupID) {
704 for($groupID = 0; $groupID < $groupCount; ++$groupID) {
715 for(
$i = 0;
$i < $groupCount; ++
$i) {
730 for(
$i = 0;
$i < $groupCount; ++
$i) {
732 $chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex(
$i)->getPlotType();
733 switch ($chartType) {
749 case 'scatterChart' :
756 $this->_graph = null;
763 $this->_graph->Stroke($outputDestination);
768 public function render($outputDestination) {
769 self::$_plotColour = 0;
771 $groupCount = $this->_chart->getPlotArea()->getPlotGroupCount();
774 if ($groupCount == 1) {
775 $chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
777 $chartTypes =
array();
778 for(
$i = 0;
$i < $groupCount; ++
$i) {
779 $chartTypes[] = $this->_chart->getPlotArea()->getPlotGroupByIndex(
$i)->getPlotType();
781 $chartTypes = array_unique($chartTypes);
782 if (count($chartTypes) == 1) {
783 $chartType = array_pop($chartTypes);
784 } elseif (count($chartTypes) == 0) {
785 echo
'Chart is not yet implemented<br />';
792 switch ($chartType) {
813 case 'doughnut3DChart' :
815 case 'doughnutChart' :
818 case 'scatterChart' :
827 case 'surface3DChart' :
829 case 'surfaceChart' :
836 echo $chartType.
' is not yet implemented<br />';
841 $this->_graph->Stroke($outputDestination);
851 $this->_graph = null;
_renderPlotStock($groupID)
_renderPlotRadar($groupID)
_renderPlotLine($groupID, $filled=false, $combination=false, $dimensions='2d')
_renderPiePlotArea($doughnut=False)
_renderCombinationChart($groupCount, $dimensions, $outputDestination)
_percentageAdjustValues($dataValues, $sumValues)
_renderCartesianPlotArea($type='textlin')
__construct(PHPExcel_Chart $chart)
Create a new PHPExcel_Chart_Renderer_jpgraph.
_getCaption($captionElement)
_renderStockChart($groupCount)
_renderBubbleChart($groupCount)
render($outputDestination)
_renderAreaChart($groupCount, $dimensions='2d')
_renderPlotScatter($groupID, $bubble)
_renderPlotContour($groupID)
static getChartRendererPath()
Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use...
Create styles array
The data for the language used.
_formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation='')
_percentageSumCalculation($groupID, $seriesCount)
_renderLineChart($groupCount, $dimensions='2d')
_formatPointMarker($seriesPlot, $markerID)
_renderContourChart($groupCount, $dimensions)
_renderRadarChart($groupCount)
_renderPieChart($groupCount, $dimensions='2d', $doughnut=False, $multiplePlots=False)
_renderBarChart($groupCount, $dimensions='2d')
_renderScatterChart($groupCount)
_renderPlotBar($groupID, $dimensions='2d')