/var/www/hkosl.com/imusiccircle/webadmin/libraies/phpoffice/phpexcel/Classes/PHPExcel/Chart/Renderer/jpgraph.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
<?php

/**
 * PHPExcel
 *
 * Copyright (c) 2006 - 2014 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    PHPExcel
 * @package        PHPExcel_Chart_Renderer
 * @copyright    Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 * @version        ##VERSION##, ##DATE##
 */


require_once(PHPExcel_Settings::getChartRendererPath().'/jpgraph.php');


/**
 * PHPExcel_Chart_Renderer_jpgraph
 *
 * @category    PHPExcel
 * @package        PHPExcel_Chart_Renderer
 * @copyright    Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
 */
class PHPExcel_Chart_Renderer_jpgraph
{
    private static 
$_width    640;

    private static 
$_height    480;

    private static 
$_colourSet = array( 'mediumpurple1',    'palegreen3',    'gold1',        'cadetblue1',
                                        
'darkmagenta',        'coral',        'dodgerblue3',    'eggplant',
                                        
'mediumblue',        'magenta',        'sandybrown',    'cyan',
                                        
'firebrick1',        'forestgreen',    'deeppink4',    'darkolivegreen',
                                        
'goldenrod2'
                                      
);

    private static 
$_markSet = array(    'diamond'    => MARK_DIAMOND,
                                        
'square'    => MARK_SQUARE,
                                        
'triangle'    => MARK_UTRIANGLE,
                                        
'x'            => MARK_X,
                                        
'star'        => MARK_STAR,
                                        
'dot'        => MARK_FILLEDCIRCLE,
                                        
'dash'        => MARK_DTRIANGLE,
                                        
'circle'    => MARK_CIRCLE,
                                        
'plus'        => MARK_CROSS
                                    
);


    private 
$_chart    null;

    private 
$_graph    null;

    private static 
$_plotColour    0;

    private static 
$_plotMark    0;


    private function 
_formatPointMarker($seriesPlot,$markerID) {
        
$plotMarkKeys array_keys(self::$_markSet);
        if (
is_null($markerID)) {
            
//    Use default plot marker (next marker in the series)
            
self::$_plotMark %= count(self::$_markSet);
            
$seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
        } elseif (
$markerID !== 'none') {
            
//    Use specified plot marker (if it exists)
            
if (isset(self::$_markSet[$markerID])) {
                
$seriesPlot->mark->SetType(self::$_markSet[$markerID]);
            } else {
                
//    If the specified plot marker doesn't exist, use default plot marker (next marker in the series)
                
self::$_plotMark %= count(self::$_markSet);
                
$seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
            }
        } else {
            
//    Hide plot marker
            
$seriesPlot->mark->Hide();
        }
        
$seriesPlot->mark->SetColor(self::$_colourSet[self::$_plotColour]);
        
$seriesPlot->mark->SetFillColor(self::$_colourSet[self::$_plotColour]);
        
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);

        return 
$seriesPlot;
    }    
//    function _formatPointMarker()


    
private function _formatDataSetLabels($groupID$datasetLabels$labelCount$rotation '') {
        
$datasetLabelFormatCode $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
        if (!
is_null($datasetLabelFormatCode)) {
            
//    Retrieve any label formatting code
            
$datasetLabelFormatCode stripslashes($datasetLabelFormatCode);
        }

        
$testCurrentIndex 0;
        foreach(
$datasetLabels as $i => $datasetLabel) {
            if (
is_array($datasetLabel)) {
                if (
$rotation == 'bar') {
                    
$datasetLabels[$i] = implode(" ",$datasetLabel);
                } else {
                    
$datasetLabel array_reverse($datasetLabel);
                    
$datasetLabels[$i] = implode("\n",$datasetLabel);
                }
            } else {
                
//    Format labels according to any formatting code
                
if (!is_null($datasetLabelFormatCode)) {
                    
$datasetLabels[$i] = PHPExcel_Style_NumberFormat::toFormattedString($datasetLabel,$datasetLabelFormatCode);
                }
            }
            ++
$testCurrentIndex;
        }

        return 
$datasetLabels;
    }    
//    function _formatDataSetLabels()


    
private function _percentageSumCalculation($groupID,$seriesCount) {
        
//    Adjust our values to a percentage value across all series in the group
        
for($i 0$i $seriesCount; ++$i) {
            if (
$i == 0) {
                
$sumValues $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
            } else {
                
$nextValues $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
                foreach(
$nextValues as $k => $value) {
                    if (isset(
$sumValues[$k])) {
                        
$sumValues[$k] += $value;
                    } else {
                        
$sumValues[$k] = $value;
                    }
                }
            }
        }

        return 
$sumValues;
    }    
//    function _percentageSumCalculation()


    
private function _percentageAdjustValues($dataValues,$sumValues) {
        foreach(
$dataValues as $k => $dataValue) {
            
$dataValues[$k] = $dataValue $sumValues[$k] * 100;
        }

        return 
$dataValues;
    }    
//    function _percentageAdjustValues()


    
private function _getCaption($captionElement) {
        
//    Read any caption
        
$caption = (!is_null($captionElement)) ? $captionElement->getCaption() : NULL;
        
//    Test if we have a title caption to display
        
if (!is_null($caption)) {
            
//    If we do, it could be a plain string or an array
            
if (is_array($caption)) {
                
//    Implode an array to a plain string
                
$caption implode('',$caption);
            }
        }
        return 
$caption;
    }    
//    function _getCaption()


    
private function _renderTitle() {
        
$title $this->_getCaption($this->_chart->getTitle());
        if (!
is_null($title)) {
            
$this->_graph->title->Set($title);
        }
    }    
//    function _renderTitle()


    
private function _renderLegend() {
        
$legend $this->_chart->getLegend();
        if (!
is_null($legend)) {
            
$legendPosition $legend->getPosition();
            
$legendOverlay $legend->getOverlay();
            switch (
$legendPosition) {
                case 
'r'    :
                    
$this->_graph->legend->SetPos(0.01,0.5,'right','center');    //    right
                    
$this->_graph->legend->SetColumns(1);
                    break;
                case 
'l'    :
                    
$this->_graph->legend->SetPos(0.01,0.5,'left','center');    //    left
                    
$this->_graph->legend->SetColumns(1);
                    break;
                case 
't'    :
                    
$this->_graph->legend->SetPos(0.5,0.01,'center','top');    //    top
                    
break;
                case 
'b'    :
                    
$this->_graph->legend->SetPos(0.5,0.99,'center','bottom');    //    bottom
                    
break;
                default        :
                    
$this->_graph->legend->SetPos(0.01,0.01,'right','top');    //    top-right
                    
$this->_graph->legend->SetColumns(1);
                    break;
            }
        } else {
            
$this->_graph->legend->Hide();
        }
    }    
//    function _renderLegend()


    
private function _renderCartesianPlotArea($type='textlin') {
        
$this->_graph = new Graph(self::$_width,self::$_height);
        
$this->_graph->SetScale($type);

        
$this->_renderTitle();

        
//    Rotate for bar rather than column chart
        
$rotation $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotDirection();
        
$reverse = ($rotation == 'bar') ? true false;

        
$xAxisLabel $this->_chart->getXAxisLabel();
        if (!
is_null($xAxisLabel)) {
            
$title $this->_getCaption($xAxisLabel);
            if (!
is_null($title)) {
                
$this->_graph->xaxis->SetTitle($title,'center');
                
$this->_graph->xaxis->title->SetMargin(35);
                if (
$reverse) {
                    
$this->_graph->xaxis->title->SetAngle(90);
                    
$this->_graph->xaxis->title->SetMargin(90);
                }
            }
        }

        
$yAxisLabel $this->_chart->getYAxisLabel();
        if (!
is_null($yAxisLabel)) {
            
$title $this->_getCaption($yAxisLabel);
            if (!
is_null($title)) {
                
$this->_graph->yaxis->SetTitle($title,'center');
                if (
$reverse) {
                    
$this->_graph->yaxis->title->SetAngle(0);
                    
$this->_graph->yaxis->title->SetMargin(-55);
                }
            }
        }
    }    
//    function _renderCartesianPlotArea()


    
private function _renderPiePlotArea($doughnut False) {
        
$this->_graph = new PieGraph(self::$_width,self::$_height);

        
$this->_renderTitle();
    }    
//    function _renderPiePlotArea()


    
private function _renderRadarPlotArea() {
        
$this->_graph = new RadarGraph(self::$_width,self::$_height);
        
$this->_graph->SetScale('lin');

        
$this->_renderTitle();
    }    
//    function _renderRadarPlotArea()


    
private function _renderPlotLine($groupID$filled false$combination false$dimensions '2d') {
        
$grouping $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();

        
$labelCount count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
        if (
$labelCount 0) {
            
$datasetLabels $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
            
$datasetLabels $this->_formatDataSetLabels($groupID$datasetLabels$labelCount);
            
$this->_graph->xaxis->SetTickLabels($datasetLabels);
        }

        
$seriesCount $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
        
$seriesPlots = array();
        if (
$grouping == 'percentStacked') {
            
$sumValues $this->_percentageSumCalculation($groupID,$seriesCount);
        }

        
//    Loop through each data series in turn
        
for($i 0$i $seriesCount; ++$i) {
            
$dataValues $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
            
$marker $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();

            if (
$grouping == 'percentStacked') {
                
$dataValues $this->_percentageAdjustValues($dataValues,$sumValues);
            }

            
//    Fill in any missing values in the $dataValues array
            
$testCurrentIndex 0;
            foreach(
$dataValues as $k => $dataValue) {
                while(
$k != $testCurrentIndex) {
                    
$dataValues[$testCurrentIndex] = null;
                    ++
$testCurrentIndex;
                }
                ++
$testCurrentIndex;
            }

            
$seriesPlot = new LinePlot($dataValues);
            if (
$combination) {
                
$seriesPlot->SetBarCenter();
            }

            if (
$filled) {
                
$seriesPlot->SetFilled(true);
                
$seriesPlot->SetColor('black');
                
$seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
            } else {
                
//    Set the appropriate plot marker
                
$this->_formatPointMarker($seriesPlot,$marker);
            }
            
$dataLabel $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
            
$seriesPlot->SetLegend($dataLabel);

            
$seriesPlots[] = $seriesPlot;
        }

        if (
$grouping == 'standard') {
            
$groupPlot $seriesPlots;
        } else {
            
$groupPlot = new AccLinePlot($seriesPlots);
        }
        
$this->_graph->Add($groupPlot);
    }    
//    function _renderPlotLine()


    
private function _renderPlotBar($groupID$dimensions '2d') {
        
$rotation $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotDirection();
        
//    Rotate for bar rather than column chart
        
if (($groupID == 0) && ($rotation == 'bar')) {
            
$this->_graph->Set90AndMargin();
        }
        
$grouping $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();

        
$labelCount count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
        if (
$labelCount 0) {
            
$datasetLabels $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
            
$datasetLabels $this->_formatDataSetLabels($groupID$datasetLabels$labelCount$rotation);
            
//    Rotate for bar rather than column chart
            
if ($rotation == 'bar') {
                
$datasetLabels array_reverse($datasetLabels);
                
$this->_graph->yaxis->SetPos('max');
                
$this->_graph->yaxis->SetLabelAlign('center','top');
                
$this->_graph->yaxis->SetLabelSide(SIDE_RIGHT);
            }
            
$this->_graph->xaxis->SetTickLabels($datasetLabels);
        }


        
$seriesCount $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
        
$seriesPlots = array();
        if (
$grouping == 'percentStacked') {
            
$sumValues $this->_percentageSumCalculation($groupID,$seriesCount);
        }

        
//    Loop through each data series in turn
        
for($j 0$j $seriesCount; ++$j) {
            
$dataValues $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
            if (
$grouping == 'percentStacked') {
                
$dataValues $this->_percentageAdjustValues($dataValues,$sumValues);
            }

            
//    Fill in any missing values in the $dataValues array
            
$testCurrentIndex 0;
            foreach(
$dataValues as $k => $dataValue) {
                while(
$k != $testCurrentIndex) {
                    
$dataValues[$testCurrentIndex] = null;
                    ++
$testCurrentIndex;
                }
                ++
$testCurrentIndex;
            }

            
//    Reverse the $dataValues order for bar rather than column chart
            
if ($rotation == 'bar') {
                
$dataValues array_reverse($dataValues);
            }
            
$seriesPlot = new BarPlot($dataValues);
            
$seriesPlot->SetColor('black');
            
$seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
            if (
$dimensions == '3d') {
                
$seriesPlot->SetShadow();
            }
            if (!
$this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) {
                
$dataLabel '';
            } else {
                
$dataLabel $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue();
            }
            
$seriesPlot->SetLegend($dataLabel);

            
$seriesPlots[] = $seriesPlot;
        }
        
//    Reverse the plot order for bar rather than column chart
        
if (($rotation == 'bar') && (!($grouping == 'percentStacked'))) {
            
$seriesPlots array_reverse($seriesPlots);
        }

        if (
$grouping == 'clustered') {
            
$groupPlot = new GroupBarPlot($seriesPlots);
        } elseif (
$grouping == 'standard') {
            
$groupPlot = new GroupBarPlot($seriesPlots);
        } else {
            
$groupPlot = new AccBarPlot($seriesPlots);
            if (
$dimensions == '3d') {
                
$groupPlot->SetShadow();
            }
        }

        
$this->_graph->Add($groupPlot);
    }    
//    function _renderPlotBar()


    
private function _renderPlotScatter($groupID,$bubble) {
        
$grouping $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
        
$scatterStyle $bubbleSize $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();

        
$seriesCount $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
        
$seriesPlots = array();

        
//    Loop through each data series in turn
        
for($i 0$i $seriesCount; ++$i) {
            
$dataValuesY $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
            
$dataValuesX $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();

            foreach(
$dataValuesY as $k => $dataValueY) {
                
$dataValuesY[$k] = $k;
            }

            
$seriesPlot = new ScatterPlot($dataValuesX,$dataValuesY);
            if (
$scatterStyle == 'lineMarker') {
                
$seriesPlot->SetLinkPoints();
                
$seriesPlot->link->SetColor(self::$_colourSet[self::$_plotColour]);
            } elseif (
$scatterStyle == 'smoothMarker') {
                
$spline = new Spline($dataValuesY,$dataValuesX);
                list(
$splineDataY,$splineDataX) = $spline->Get(count($dataValuesX) * self::$_width 20);
                
$lplot = new LinePlot($splineDataX,$splineDataY);
                
$lplot->SetColor(self::$_colourSet[self::$_plotColour]);

                
$this->_graph->Add($lplot);
            }

            if (
$bubble) {
                
$this->_formatPointMarker($seriesPlot,'dot');
                
$seriesPlot->mark->SetColor('black');
                
$seriesPlot->mark->SetSize($bubbleSize);
            } else {
                
$marker $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
                
$this->_formatPointMarker($seriesPlot,$marker);
            }
            
$dataLabel $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
            
$seriesPlot->SetLegend($dataLabel);

            
$this->_graph->Add($seriesPlot);
        }
    }    
//    function _renderPlotScatter()


    
private function _renderPlotRadar($groupID) {
        
$radarStyle $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();

        
$seriesCount $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
        
$seriesPlots = array();

        
//    Loop through each data series in turn
        
for($i 0$i $seriesCount; ++$i) {
            
$dataValuesY $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
            
$dataValuesX $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
            
$marker $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();

            
$dataValues = array();
            foreach(
$dataValuesY as $k => $dataValueY) {
                
$dataValues[$k] = implode(' ',array_reverse($dataValueY));
            }
            
$tmp array_shift($dataValues);
            
$dataValues[] = $tmp;
            
$tmp array_shift($dataValuesX);
            
$dataValuesX[] = $tmp;

            
$this->_graph->SetTitles(array_reverse($dataValues));

            
$seriesPlot = new RadarPlot(array_reverse($dataValuesX));

            
$dataLabel $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
            
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
            if (
$radarStyle == 'filled') {
                
$seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour]);
            }
            
$this->_formatPointMarker($seriesPlot,$marker);
            
$seriesPlot->SetLegend($dataLabel);

            
$this->_graph->Add($seriesPlot);
        }
    }    
//    function _renderPlotRadar()


    
private function _renderPlotContour($groupID) {
        
$contourStyle $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();

        
$seriesCount $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
        
$seriesPlots = array();

        
$dataValues = array();
        
//    Loop through each data series in turn
        
for($i 0$i $seriesCount; ++$i) {
            
$dataValuesY $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
            
$dataValuesX $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();

            
$dataValues[$i] = $dataValuesX;
        }
        
$seriesPlot = new ContourPlot($dataValues);

        
$this->_graph->Add($seriesPlot);
    }    
//    function _renderPlotContour()


    
private function _renderPlotStock($groupID) {
        
$seriesCount $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
        
$plotOrder $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder();

        
$dataValues = array();
        
//    Loop through each data series in turn and build the plot arrays
        
foreach($plotOrder as $i => $v) {
            
$dataValuesX $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($v)->getDataValues();
            foreach(
$dataValuesX as $j => $dataValueX) {
                
$dataValues[$plotOrder[$i]][$j] = $dataValueX;
            }
        }
        if(empty(
$dataValues)) {
            return;
        }

        
$dataValuesPlot = array();
        
// Flatten the plot arrays to a single dimensional array to work with jpgraph
        
for($j 0$j count($dataValues[0]); $j++) {
            for(
$i 0$i $seriesCount$i++) {
                
$dataValuesPlot[] = $dataValues[$i][$j];
            }
        }

        
// Set the x-axis labels
        
$labelCount count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
        if (
$labelCount 0) {
            
$datasetLabels $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
            
$datasetLabels $this->_formatDataSetLabels($groupID$datasetLabels$labelCount);
            
$this->_graph->xaxis->SetTickLabels($datasetLabels);
        }

        
$seriesPlot = new StockPlot($dataValuesPlot);
        
$seriesPlot->SetWidth(20);

        
$this->_graph->Add($seriesPlot);
    }    
//    function _renderPlotStock()


    
private function _renderAreaChart($groupCount$dimensions '2d') {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_line.php');

        
$this->_renderCartesianPlotArea();

        for(
$i 0$i $groupCount; ++$i) {
            
$this->_renderPlotLine($i,True,False,$dimensions);
        }
    }    
//    function _renderAreaChart()


    
private function _renderLineChart($groupCount$dimensions '2d') {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_line.php');

        
$this->_renderCartesianPlotArea();

        for(
$i 0$i $groupCount; ++$i) {
            
$this->_renderPlotLine($i,False,False,$dimensions);
        }
    }    
//    function _renderLineChart()


    
private function _renderBarChart($groupCount$dimensions '2d') {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_bar.php');

        
$this->_renderCartesianPlotArea();

        for(
$i 0$i $groupCount; ++$i) {
            
$this->_renderPlotBar($i,$dimensions);
        }
    }    
//    function _renderBarChart()


    
private function _renderScatterChart($groupCount) {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_scatter.php');
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_regstat.php');
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_line.php');

        
$this->_renderCartesianPlotArea('linlin');

        for(
$i 0$i $groupCount; ++$i) {
            
$this->_renderPlotScatter($i,false);
        }
    }    
//    function _renderScatterChart()


    
private function _renderBubbleChart($groupCount) {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_scatter.php');

        
$this->_renderCartesianPlotArea('linlin');

        for(
$i 0$i $groupCount; ++$i) {
            
$this->_renderPlotScatter($i,true);
        }
    }    
//    function _renderBubbleChart()


    
private function _renderPieChart($groupCount$dimensions '2d'$doughnut False$multiplePlots False) {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_pie.php');
        if (
$dimensions == '3d') {
            require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_pie3d.php');
        }

        
$this->_renderPiePlotArea($doughnut);

        
$iLimit = ($multiplePlots) ? $groupCount 1;
        for(
$groupID 0$groupID $iLimit; ++$groupID) {
            
$grouping $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
            
$exploded $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
            if (
$groupID == 0) {
                
$labelCount count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
                if (
$labelCount 0) {
                    
$datasetLabels $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
                    
$datasetLabels $this->_formatDataSetLabels($groupID$datasetLabels$labelCount);
                }
            }

            
$seriesCount $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
            
$seriesPlots = array();
            
//    For pie charts, we only display the first series: doughnut charts generally display all series
            
$jLimit = ($multiplePlots) ? $seriesCount 1;
            
//    Loop through each data series in turn
            
for($j 0$j $jLimit; ++$j) {
                
$dataValues $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();

                
//    Fill in any missing values in the $dataValues array
                
$testCurrentIndex 0;
                foreach(
$dataValues as $k => $dataValue) {
                    while(
$k != $testCurrentIndex) {
                        
$dataValues[$testCurrentIndex] = null;
                        ++
$testCurrentIndex;
                    }
                    ++
$testCurrentIndex;
                }

                if (
$dimensions == '3d') {
                    
$seriesPlot = new PiePlot3D($dataValues);
                } else {
                    if (
$doughnut) {
                        
$seriesPlot = new PiePlotC($dataValues);
                    } else {
                        
$seriesPlot = new PiePlot($dataValues);
                    }
                }

                if (
$multiplePlots) {
                    
$seriesPlot->SetSize(($jLimit-$j) / ($jLimit 4));
                }

                if (
$doughnut) {
                    
$seriesPlot->SetMidColor('white');
                }

                
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
                if (
count($datasetLabels) > 0)
                    
$seriesPlot->SetLabels(array_fill(0,count($datasetLabels),''));
                if (
$dimensions != '3d') {
                    
$seriesPlot->SetGuideLines(false);
                }
                if (
$j == 0) {
                    if (
$exploded) {
                        
$seriesPlot->ExplodeAll();
                    }
                    
$seriesPlot->SetLegends($datasetLabels);
                }

                
$this->_graph->Add($seriesPlot);
            }
        }
    }    
//    function _renderPieChart()


    
private function _renderRadarChart($groupCount) {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_radar.php');

        
$this->_renderRadarPlotArea();

        for(
$groupID 0$groupID $groupCount; ++$groupID) {
            
$this->_renderPlotRadar($groupID);
        }
    }    
//    function _renderRadarChart()


    
private function _renderStockChart($groupCount) {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_stock.php');

        
$this->_renderCartesianPlotArea('intint');

        for(
$groupID 0$groupID $groupCount; ++$groupID) {
            
$this->_renderPlotStock($groupID);
        }
    }    
//    function _renderStockChart()


    
private function _renderContourChart($groupCount,$dimensions) {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_contour.php');

        
$this->_renderCartesianPlotArea('intint');

        for(
$i 0$i $groupCount; ++$i) {
            
$this->_renderPlotContour($i);
        }
    }    
//    function _renderContourChart()


    
private function _renderCombinationChart($groupCount,$dimensions,$outputDestination) {
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_line.php');
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_bar.php');
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_scatter.php');
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_regstat.php');
        require_once(
PHPExcel_Settings::getChartRendererPath().'jpgraph_line.php');

        
$this->_renderCartesianPlotArea();

        for(
$i 0$i $groupCount; ++$i) {
            
$dimensions null;
            
$chartType $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
            switch (
$chartType) {
                case 
'area3DChart' :
                    
$dimensions '3d';
                case 
'areaChart' :
                    
$this->_renderPlotLine($i,True,True,$dimensions);
                    break;
                case 
'bar3DChart' :
                    
$dimensions '3d';
                case 
'barChart' :
                    
$this->_renderPlotBar($i,$dimensions);
                    break;
                case 
'line3DChart' :
                    
$dimensions '3d';
                case 
'lineChart' :
                    
$this->_renderPlotLine($i,False,True,$dimensions);
                    break;
                case 
'scatterChart' :
                    
$this->_renderPlotScatter($i,false);
                    break;
                case 
'bubbleChart' :
                    
$this->_renderPlotScatter($i,true);
                    break;
                default    :
                    
$this->_graph null;
                    return 
false;
            }
        }

        
$this->_renderLegend();

        
$this->_graph->Stroke($outputDestination);
        return 
true;
    }    
//    function _renderCombinationChart()


    
public function render($outputDestination) {
        
self::$_plotColour 0;

        
$groupCount $this->_chart->getPlotArea()->getPlotGroupCount();

        
$dimensions null;
        if (
$groupCount == 1) {
            
$chartType $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
        } else {
            
$chartTypes = array();
            for(
$i 0$i $groupCount; ++$i) {
                
$chartTypes[] = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
            }
            
$chartTypes array_unique($chartTypes);
            if (
count($chartTypes) == 1) {
                
$chartType array_pop($chartTypes);
            } elseif (
count($chartTypes) == 0) {
                echo 
'Chart is not yet implemented<br />';
                return 
false;
            } else {
                return 
$this->_renderCombinationChart($groupCount,$dimensions,$outputDestination);
            }
        }

        switch (
$chartType) {
            case 
'area3DChart' :
                
$dimensions '3d';
            case 
'areaChart' :
                
$this->_renderAreaChart($groupCount,$dimensions);
                break;
            case 
'bar3DChart' :
                
$dimensions '3d';
            case 
'barChart' :
                
$this->_renderBarChart($groupCount,$dimensions);
                break;
            case 
'line3DChart' :
                
$dimensions '3d';
            case 
'lineChart' :
                
$this->_renderLineChart($groupCount,$dimensions);
                break;
            case 
'pie3DChart' :
                
$dimensions '3d';
            case 
'pieChart' :
                
$this->_renderPieChart($groupCount,$dimensions,False,False);
                break;
            case 
'doughnut3DChart' :
                
$dimensions '3d';
            case 
'doughnutChart' :
                
$this->_renderPieChart($groupCount,$dimensions,True,True);
                break;
            case 
'scatterChart' :
                
$this->_renderScatterChart($groupCount);
                break;
            case 
'bubbleChart' :
                
$this->_renderBubbleChart($groupCount);
                break;
            case 
'radarChart' :
                
$this->_renderRadarChart($groupCount);
                break;
            case 
'surface3DChart' :
                
$dimensions '3d';
            case 
'surfaceChart' :
                
$this->_renderContourChart($groupCount,$dimensions);
                break;
            case 
'stockChart' :
                
$this->_renderStockChart($groupCount,$dimensions);
                break;
            default    :
                echo 
$chartType.' is not yet implemented<br />';
                return 
false;
        }
        
$this->_renderLegend();

        
$this->_graph->Stroke($outputDestination);
        return 
true;
    }    
//    function render()


    /**
     * Create a new PHPExcel_Chart_Renderer_jpgraph
     */
    
public function __construct(PHPExcel_Chart $chart)
    {
        
$this->_graph    null;
        
$this->_chart    $chart;
    }    
//    function __construct()

}    //    PHPExcel_Chart_Renderer_jpgraph