Completed
Pull Request — develop (#635)
by Franck
02:08
created

Sample_05_Chart.php ➔ fnSlide_Bar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 52
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 52
loc 52
rs 9.0472
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
include_once 'Sample_Header.php';
4
5
use PhpOffice\PhpPresentation\PhpPresentation;
6
use PhpOffice\PhpPresentation\Shape\Chart\Type\Area;
7
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Bar.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
9
use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
10
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie;
11
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
12
use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
13
use PhpOffice\PhpPresentation\Shape\Chart\Series;
14
use PhpOffice\PhpPresentation\Style\Alignment;
15
use PhpOffice\PhpPresentation\Style\Border;
16
use PhpOffice\PhpPresentation\Style\Color;
17
use PhpOffice\PhpPresentation\Style\Fill;
18
use PhpOffice\PhpPresentation\Style\Shadow;
19
20
function fnSlide_Area(PhpPresentation $objPHPPresentation) {
21
    global $oFill;
22
    global $oShadow;
23
24
    // Generate sample data for chart
25
    echo date('H:i:s') . ' Generate sample data for chart' . EOL;
26
    $seriesData = array(
27
        'Monday' => 12,
28
        'Tuesday' => 15,
29
        'Wednesday' => 13,
30
        'Thursday' => 17,
31
        'Friday' => 14,
32
        'Saturday' => 9,
33
        'Sunday' => 7
34
    );
35
36
    // Create templated slide
37
    echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
38
    $currentSlide = createTemplatedSlide($objPHPPresentation);
39
40
    // Create a line chart (that should be inserted in a shape)
41
    echo date('H:i:s') . ' Create a area chart (that should be inserted in a chart shape)' . EOL;
42
    $areaChart = new Area();
43
    $series = new Series('Downloads', $seriesData);
44
    $series->setShowSeriesName(true);
45
    $series->setShowValue(true);
46
    $series->getFill()->setStartColor(new Color('FF93A9CE'));
47
    $series->setLabelPosition(Series::LABEL_INSIDEEND);
48
    $areaChart->addSeries($series);
49
50
    // Create a shape (chart)
51
    echo date('H:i:s') . ' Create a shape (chart)' . EOL;
52
    $shape = $currentSlide->createChartShape();
53
    $shape->getTitle()->setVisible(false);
54
    $shape->setName('PHPPresentation Daily Downloads')->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
55
    $shape->setShadow($oShadow);
56
    $shape->setFill($oFill);
57
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
58
    $shape->getTitle()->setText('PHPPresentation Daily Downloads');
59
    $shape->getTitle()->getFont()->setItalic(true);
60
    $shape->getPlotArea()->setType($areaChart);
61
    $shape->getPlotArea()->getAxisX()->setTitle('Axis X');
62
    $shape->getPlotArea()->getAxisY()->setTitle('Axis Y');
63
    $shape->getView3D()->setRotationX(30);
64
    $shape->getView3D()->setPerspective(30);
65
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
66
    $shape->getLegend()->getFont()->setItalic(true);
67
}
68
69 View Code Duplication
function fnSlide_Bar(PhpPresentation $objPHPPresentation) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    global $oFill;
71
    global $oShadow;
72
73
    // Create templated slide
74
    echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
75
    $currentSlide = createTemplatedSlide($objPHPPresentation);
76
77
    // Generate sample data for first chart
78
    echo date('H:i:s') . ' Generate sample data for chart'.EOL;
79
    $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
80
    $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
81
82
    // Create a bar chart (that should be inserted in a shape)
83
    echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)'.EOL;
84
    $barChart = new Bar();
85
    $barChart->setGapWidthPercent(158);
86
    $series1 = new Series('2009', $series1Data);
87
    $series1->setShowSeriesName(true);
88
    $series1->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4F81BD'));
89
    $series1->getFont()->getColor()->setRGB('00FF00');
90
    $series1->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
91
    $series2 = new Series('2010', $series2Data);
92
    $series2->setShowSeriesName(true);
93
    $series2->getFont()->getColor()->setRGB('FF0000');
94
    $series2->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFC0504D'));
95
    $series2->setLabelPosition(Series::LABEL_INSIDEEND);
96
    $barChart->addSeries($series1);
97
    $barChart->addSeries($series2);
98
99
    // Create a shape (chart)
100
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
101
    $shape = $currentSlide->createChartShape();
102
    $shape->setName('PHPPresentation Monthly Downloads')
103
        ->setResizeProportional(false)
104
        ->setHeight(550)
105
        ->setWidth(700)
106
        ->setOffsetX(120)
107
        ->setOffsetY(80);
108
    $shape->setShadow($oShadow);
109
    $shape->setFill($oFill);
110
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
111
    $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
112
    $shape->getTitle()->getFont()->setItalic(true);
113
    $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
114
    $shape->getPlotArea()->getAxisX()->setTitle('Month');
115
    $shape->getPlotArea()->getAxisY()->getFont()->getColor()->setRGB('00FF00');
116
    $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
117
    $shape->getPlotArea()->setType($barChart);
118
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
119
    $shape->getLegend()->getFont()->setItalic(true);
120
}
121
122
function fnSlide_BarHorizontal(PhpPresentation $objPHPPresentation) {
123
    global $oFill;
124
    global $oShadow;
125
126
    // Create a bar chart (that should be inserted in a shape)
127
    echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) '.EOL;
128
    $barChartHorz = clone $objPHPPresentation->getSlide(1)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
129
    $barChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
130
131
    // Create templated slide
132
    echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
133
    $currentSlide = createTemplatedSlide($objPHPPresentation);
134
135
    // Create a shape (chart)
136
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
137
    $shape = $currentSlide->createChartShape();
138
    $shape->setName('PHPPresentation Monthly Downloads')
139
        ->setResizeProportional(false)
140
        ->setHeight(550)
141
        ->setWidth(700)
142
        ->setOffsetX(120)
143
        ->setOffsetY(80);
144
    $shape->setShadow($oShadow);
145
    $shape->setFill($oFill);
146
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
147
    $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
148
    $shape->getTitle()->getFont()->setItalic(true);
149
    $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
150
    $shape->getPlotArea()->getAxisX()->setTitle('Month');
151
    $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
152
    $shape->getPlotArea()->setType($barChartHorz);
153
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
154
    $shape->getLegend()->getFont()->setItalic(true);
155
}
156
157
function fnSlide_BarStacked(PhpPresentation $objPHPPresentation) {
158
    global $oFill;
159
    global $oShadow;
160
161
    // Create templated slide
162
    echo EOL . date( 'H:i:s' ) . ' Create templated slide' . EOL;
163
    $currentSlide = createTemplatedSlide( $objPHPPresentation );
164
165
    // Generate sample data for first chart
166
    echo date( 'H:i:s' ) . ' Generate sample data for chart' . EOL;
167
    $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
168
    $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
169
    $series3Data = array('Jan' => 233, 'Feb' => 146, 'Mar' => 238, 'Apr' => 175, 'May' => 108, 'Jun' => 257, 'Jul' => 199, 'Aug' => 201, 'Sep' => 88, 'Oct' => 147, 'Nov' => 287, 'Dec' => 105);
170
171
    // Create a bar chart (that should be inserted in a shape)
172
    echo date( 'H:i:s' ) . ' Create a stacked bar chart (that should be inserted in a chart shape)' . EOL;
173
    $StackedBarChart = new Bar();
174
    $series1 = new Series( '2009', $series1Data );
175
    $series1->setShowSeriesName(false);
176
    $series1->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF4F81BD' ) );
177
    $series1->getFont()->getColor()->setRGB( '00FF00' );
178
    $series1->setShowValue(true);
179
    $series1->setShowPercentage(false);
180
    $series2 = new Series( '2010', $series2Data );
181
    $series2->setShowSeriesName(false);
182
    $series2->getFont()->getColor()->setRGB( 'FF0000' );
183
    $series2->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FFC0504D' ) );
184
    $series2->setShowValue(true);
185
    $series2->setShowPercentage(false);
186
    $series3 = new Series( '2011', $series3Data );
187
    $series3->setShowSeriesName(false);
188
    $series3->getFont()->getColor()->setRGB( 'FF0000' );
189
    $series3->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF804DC0' ) );
190
    $series3->setShowValue(true);
191
    $series3->setShowPercentage(false);
192
    $StackedBarChart->addSeries( $series1 );
193
    $StackedBarChart->addSeries( $series2 );
194
    $StackedBarChart->addSeries( $series3 );
195
    $StackedBarChart->setBarGrouping( Bar::GROUPING_STACKED );
196
    // Create a shape (chart)
197
    echo date( 'H:i:s' ) . ' Create a shape (chart)' . EOL;
198
    $shape = $currentSlide->createChartShape();
199
    $shape->setName( 'PHPPresentation Monthly Downloads' )
200
        ->setResizeProportional(false)
201
        ->setHeight( 550 )
202
        ->setWidth( 700 )
203
        ->setOffsetX( 120 )
204
        ->setOffsetY( 80 );
205
    $shape->setShadow( $oShadow );
206
    $shape->setFill( $oFill );
207
    $shape->getBorder()->setLineStyle( Border::LINE_SINGLE );
208
    $shape->getTitle()->setText( 'PHPPresentation Monthly Downloads' );
209
    $shape->getTitle()->getFont()->setItalic(true);
210
    $shape->getTitle()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_RIGHT );
211
    $shape->getPlotArea()->getAxisX()->setTitle( 'Month' );
212
    $shape->getPlotArea()->getAxisY()->setTitle( 'Downloads' );
213
    $shape->getPlotArea()->setType( $StackedBarChart );
214
    $shape->getLegend()->getBorder()->setLineStyle( Border::LINE_SINGLE );
215
    $shape->getLegend()->getFont()->setItalic(true);
216
}
217
218
function fnSlide_BarPercentStacked(PhpPresentation $objPHPPresentation) {
219
    global $oFill;
220
    global $oShadow;
221
222
    // Create templated slide
223
    echo EOL . date( 'H:i:s' ) . ' Create templated slide' . EOL;
224
    $currentSlide = createTemplatedSlide( $objPHPPresentation );
225
226
    // Generate sample data for first chart
227
    echo date( 'H:i:s' ) . ' Generate sample data for chart' . EOL;
228
    $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
229
    $Series1Sum = array_sum($series1Data);
230
    foreach ($series1Data as $CatName => $Value) {
231
        $series1Data[$CatName]= round($Value / $Series1Sum, 2);
232
    }
233
    $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
234
    $Series2Sum = array_sum($series2Data);
235
    foreach ($series2Data as $CatName => $Value) {
236
        $series2Data[$CatName] = round($Value / $Series2Sum, 2);
237
    }
238
    $series3Data = array('Jan' => 233, 'Feb' => 146, 'Mar' => 238, 'Apr' => 175, 'May' => 108, 'Jun' => 257, 'Jul' => 199, 'Aug' => 201, 'Sep' => 88, 'Oct' => 147, 'Nov' => 287, 'Dec' => 105);
239
    $Series3Sum = array_sum( $series3Data );
240
    foreach ($series3Data as $CatName => $Value) {
241
        $series3Data[$CatName] = round($Value / $Series3Sum,2);
242
    }
243
244
    // Create a bar chart (that should be inserted in a shape)
245
    echo date( 'H:i:s' ) . ' Create a percent stacked horizontal bar chart (that should be inserted in a chart shape)' . EOL;
246
    $PercentStackedBarChartHoriz = new Bar();
247
    $series1 = new Series( '2009', $series1Data );
248
    $series1->setShowSeriesName(false);
249
    $series1->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF4F81BD' ) );
250
    $series1->getFont()->getColor()->setRGB( '00FF00' );
251
    $series1->setShowValue(true);
252
    $series1->setShowPercentage(false);
253
    // Set Data Label Format For Chart To Display Percent
254
    $series1->setDlblNumFormat( '#%' );
255
    $series2 = new Series( '2010', $series2Data );
256
    $series2->setShowSeriesName(false);
257
    $series2->getFont()->getColor()->setRGB( 'FF0000' );
258
    $series2->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FFC0504D' ) );
259
    $series2->setShowValue(true);
260
    $series2->setShowPercentage(false);
261
    $series2->setDlblNumFormat( '#%' );
262
    $series3 = new Series( '2011', $series3Data );
263
    $series3->setShowSeriesName(false);
264
    $series3->getFont()->getColor()->setRGB( 'FF0000' );
265
    $series3->getFill()->setFillType( Fill::FILL_SOLID )->setStartColor( new Color( 'FF804DC0' ) );
266
    $series3->setShowValue(true);
267
    $series3->setShowPercentage(false);
268
    $series3->setDlblNumFormat( '#%' );
269
    $PercentStackedBarChartHoriz->addSeries( $series1 );
270
    $PercentStackedBarChartHoriz->addSeries( $series2 );
271
    $PercentStackedBarChartHoriz->addSeries( $series3 );
272
    $PercentStackedBarChartHoriz->setBarGrouping( Bar::GROUPING_PERCENTSTACKED );
273
    $PercentStackedBarChartHoriz->setBarDirection( Bar3D::DIRECTION_HORIZONTAL );
274
    // Create a shape (chart)
275
    echo date( 'H:i:s' ) . ' Create a shape (chart)' . EOL;
276
    $shape = $currentSlide->createChartShape();
277
    $shape->setName( 'PHPPresentation Monthly Downloads' )
278
        ->setResizeProportional(false)
279
        ->setHeight( 550 )
280
        ->setWidth( 700 )
281
        ->setOffsetX( 120 )
282
        ->setOffsetY( 80 );
283
    $shape->setShadow( $oShadow );
284
    $shape->setFill( $oFill );
285
    $shape->getBorder()->setLineStyle( Border::LINE_SINGLE );
286
    $shape->getTitle()->setText( 'PHPPresentation Monthly Downloads' );
287
    $shape->getTitle()->getFont()->setItalic(true);
288
    $shape->getTitle()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_RIGHT );
289
    $shape->getPlotArea()->getAxisX()->setTitle( 'Month' );
290
    $shape->getPlotArea()->getAxisY()->setTitle( 'Downloads' );
291
    $shape->getPlotArea()->setType( $PercentStackedBarChartHoriz );
292
    $shape->getLegend()->getBorder()->setLineStyle( Border::LINE_SINGLE );
293
    $shape->getLegend()->getFont()->setItalic(true);
294
}
295
296 View Code Duplication
function fnSlide_Bar3D(PhpPresentation $objPHPPresentation) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
297
    global $oFill;
298
    global $oShadow;
299
300
    // Create templated slide
301
    echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
302
    $currentSlide = createTemplatedSlide($objPHPPresentation);
303
304
    // Generate sample data for first chart
305
    echo date('H:i:s') . ' Generate sample data for chart'.EOL;
306
    $series1Data = array('Jan' => 133, 'Feb' => 99, 'Mar' => 191, 'Apr' => 205, 'May' => 167, 'Jun' => 201, 'Jul' => 240, 'Aug' => 226, 'Sep' => 255, 'Oct' => 264, 'Nov' => 283, 'Dec' => 293);
307
    $series2Data = array('Jan' => 266, 'Feb' => 198, 'Mar' => 271, 'Apr' => 305, 'May' => 267, 'Jun' => 301, 'Jul' => 340, 'Aug' => 326, 'Sep' => 344, 'Oct' => 364, 'Nov' => 383, 'Dec' => 379);
308
309
    // Create a bar chart (that should be inserted in a shape)
310
    echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)'.EOL;
311
    $bar3DChart = new Bar3D();
312
    $series1 = new Series('2009', $series1Data);
313
    $series1->setShowSeriesName(true);
314
    $series1->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4F81BD'));
315
    $series1->getFont()->getColor()->setRGB('00FF00');
316
    $series1->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
317
    $series2 = new Series('2010', $series2Data);
318
    $series2->setShowSeriesName(true);
319
    $series2->getFont()->getColor()->setRGB('FF0000');
320
    $series2->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFC0504D'));
321
    $bar3DChart->addSeries($series1);
322
    $bar3DChart->addSeries($series2);
323
324
    // Create a shape (chart)
325
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
326
    $shape = $currentSlide->createChartShape();
327
    $shape->setName('PHPPresentation Monthly Downloads')
328
        ->setResizeProportional(false)
329
        ->setHeight(550)
330
        ->setWidth(700)
331
        ->setOffsetX(120)
332
        ->setOffsetY(80);
333
    $shape->setShadow($oShadow);
334
    $shape->setFill($oFill);
335
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
336
    $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
337
    $shape->getTitle()->getFont()->setItalic(true);
338
    $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
339
    $shape->getPlotArea()->getAxisX()->setTitle('Month');
340
    $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
341
    $shape->getPlotArea()->setType($bar3DChart);
342
    $shape->getView3D()->setRightAngleAxes(true);
343
    $shape->getView3D()->setRotationX(20);
344
    $shape->getView3D()->setRotationY(20);
345
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
346
    $shape->getLegend()->getFont()->setItalic(true);
347
}
348
349
function fnSlide_Bar3DHorizontal(PhpPresentation $objPHPPresentation) {
350
    global $oFill;
351
    global $oShadow;
352
    
353
    // Create a bar chart (that should be inserted in a shape)
354
    echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) '.EOL;
355
    $bar3DChartHorz = clone $objPHPPresentation->getSlide(5)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
356
    $bar3DChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
357
    
358
    // Create templated slide
359
    echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
360
    $currentSlide = createTemplatedSlide($objPHPPresentation);
361
    
362
    // Create a shape (chart)
363
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
364
    $shape = $currentSlide->createChartShape();
365
    $shape->setName('PHPPresentation Monthly Downloads')
366
            ->setResizeProportional(false)
367
            ->setHeight(550)
368
            ->setWidth(700)
369
            ->setOffsetX(120)
370
            ->setOffsetY(80);
371
    $shape->setShadow($oShadow);
372
    $shape->setFill($oFill);
373
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
374
    $shape->getTitle()->setText('PHPPresentation Monthly Downloads');
375
    $shape->getTitle()->getFont()->setItalic(true);
376
    $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
377
    $shape->getPlotArea()->getAxisX()->setTitle('Month');
378
    $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
379
    $shape->getPlotArea()->setType($bar3DChartHorz);
380
    $shape->getView3D()->setRightAngleAxes(true);
381
    $shape->getView3D()->setRotationX(20);
382
    $shape->getView3D()->setRotationY(20);
383
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
384
    $shape->getLegend()->getFont()->setItalic(true);
385
}
386
387
function fnSlide_Doughnut(PhpPresentation $objPHPPresentation)
388
{
389
    global $oFill;
390
    global $oShadow;
391
392
    // Create templated slide
393
    echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
394
    $currentSlide = createTemplatedSlide($objPHPPresentation);
395
396
    // Generate sample data for second chart
397
    echo date('H:i:s') . ' Generate sample data for chart' . EOL;
398
    $seriesData = array('Monday' => 18, 'Tuesday' => 23, 'Wednesday' => 14, 'Thursday' => 12, 'Friday' => 20, 'Saturday' => 8, 'Sunday' => 10);
399
400
    // Create a doughnut chart (that should be inserted in a shape)
401
    echo date('H:i:s') . ' Create a non-3D Doughnut chart (that should be inserted in a chart shape)' . EOL;
402
    $doughnutChart = new \PhpOffice\PhpPresentation\Shape\Chart\Type\Doughnut();
403
    $doughnutChart->setHoleSize(43);
404
    $series = new Series('Downloads', $seriesData);
405
    $series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF7CB5EC'));
406
    $series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF434348'));
407
    $series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF90ED7D'));
408
    $series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF7A35C'));
409
    $series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8085E9'));
410
    $series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF15C80'));
411
    $series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE4D354'));
412
    $series->setShowPercentage(true);
413
    $series->setShowValue(false);
414
    $series->setShowSeriesName(false);
415
    $series->setShowCategoryName(true);
416
    $series->setDlblNumFormat('%d');
417
    $series->setSeparator(' > ');
418
    $series->getFont()->getColor()->setRGB('FFFF00');
419
    $series->getFont()->setBold(true);
420
    $doughnutChart->addSeries($series);
421
422
    // Create a shape (chart)
423
    echo date('H:i:s') . ' Create a shape (chart)' . EOL;
424
    $shape = $currentSlide->createChartShape();
425
    $shape->setName('PHPPresentation Daily Downloads')
426
        ->setResizeProportional(false)
427
        ->setHeight(550)
428
        ->setWidth(700)
429
        ->setOffsetX(120)
430
        ->setOffsetY(80);
431
    $shape->setShadow($oShadow);
432
    $shape->setFill($oFill);
433
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
434
    $shape->getTitle()->setText('PHPPresentation Daily Downloads');
435
    $shape->getTitle()->getFont()->setItalic(true);
436
    $shape->getPlotArea()->setType($doughnutChart);
437
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
438
    $shape->getLegend()->getFont()->setItalic(true);
439
    $shape->getLegend()->setPosition(\PhpOffice\PhpPresentation\Shape\Chart\Legend::POSITION_LEFT);
440
}
441
442
function fnSlide_Pie3D(PhpPresentation $objPHPPresentation) {
443
    global $oFill;
444
    global $oShadow;
445
    
446
    // Create templated slide
447
    echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
448
    $currentSlide = createTemplatedSlide($objPHPPresentation);
449
    
450
    // Generate sample data for second chart
451
    echo date('H:i:s') . ' Generate sample data for chart'.EOL;
452
    $seriesData = array('Monday' => 12, 'Tuesday' => 15, 'Wednesday' => 13, 'Thursday' => 17, 'Friday' => 14, 'Saturday' => 9, 'Sunday' => 7);
453
    
454
    // Create a pie chart (that should be inserted in a shape)
455
    echo date('H:i:s') . ' Create a pie chart (that should be inserted in a chart shape)'.EOL;
456
    $pie3DChart = new Pie3D();
457
    $pie3DChart->setExplosion(20);
458
    $series = new Series('Downloads', $seriesData);
459
    $series->setShowSeriesName(true);
460
    $series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8'));
461
    $series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFAB4744'));
462
    $series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8AA64F'));
463
    $series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF725990'));
464
    $series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4299B0'));
465
    $series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFDC853E'));
466
    $series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF93A9CE'));
467
    $pie3DChart->addSeries($series);
468
469
    // Create a shape (chart)
470
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
471
    $shape = $currentSlide->createChartShape();
472
    $shape->setName('PHPPresentation Daily Downloads')
473
          ->setResizeProportional(false)
474
          ->setHeight(550)
475
          ->setWidth(700)
476
          ->setOffsetX(120)
477
          ->setOffsetY(80);
478
    $shape->setShadow($oShadow);
479
    $shape->setFill($oFill);
480
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
481
    $shape->getTitle()->setText('PHPPresentation Daily Downloads');
482
    $shape->getTitle()->getFont()->setItalic(true);
483
    $shape->getPlotArea()->setType($pie3DChart);
484
    $shape->getView3D()->setRotationX(30);
485
    $shape->getView3D()->setPerspective(30);
486
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
487
    $shape->getLegend()->getFont()->setItalic(true);
488
}
489
490
function fnSlide_Pie(PhpPresentation $objPHPPresentation) {
491
    global $oFill;
492
    global $oShadow;
493
494
    // Create templated slide
495
    echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
496
    $currentSlide = createTemplatedSlide($objPHPPresentation);
497
498
    // Generate sample data for second chart
499
    echo date('H:i:s') . ' Generate sample data for chart'.EOL;
500
    $seriesData = array('Monday' => 18, 'Tuesday' => 23, 'Wednesday' => 14, 'Thursday' => 12, 'Friday' => 20, 'Saturday' => 8, 'Sunday' => 10);
501
502
    // Create a pie chart (that should be inserted in a shape)
503
    echo date('H:i:s') . ' Create a non-3D pie chart (that should be inserted in a chart shape)'.EOL;
504
    $pieChart = new Pie();
505
    $pieChart->setExplosion(15);
506
    $series = new Series('Downloads', $seriesData);
507
    $series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF7CB5EC'));
508
    $series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF434348'));
509
    $series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF90ED7D'));
510
    $series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF7A35C'));
511
    $series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8085E9'));
512
    $series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF15C80'));
513
    $series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE4D354'));
514
    $series->setShowPercentage(true);
515
    $series->setShowValue(false);
516
    $series->setShowSeriesName(false);
517
    $series->setShowCategoryName(true);
518
    $series->setDlblNumFormat('%d');
519
    $pieChart->addSeries($series);
520
521
    // Create a shape (chart)
522
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
523
    $shape = $currentSlide->createChartShape();
524
    $shape->setName('PHPPresentation Daily Downloads')
525
          ->setResizeProportional(false)
526
          ->setHeight(550)
527
          ->setWidth(700)
528
          ->setOffsetX(120)
529
          ->setOffsetY(80);
530
    $shape->setShadow($oShadow);
531
    $shape->setFill($oFill);
532
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
533
    $shape->getTitle()->setText('PHPPresentation Daily Downloads');
534
    $shape->getTitle()->getFont()->setItalic(true);
535
    $shape->getPlotArea()->setType($pieChart);
536
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
537
    $shape->getLegend()->getFont()->setItalic(true);
538
}
539
540
function fnSlide_Scatter(PhpPresentation $objPHPPresentation) {
541
    global $oFill;
542
    global $oShadow;
543
    
544
    // Create templated slide
545
    echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
546
    $currentSlide = createTemplatedSlide($objPHPPresentation); // local function
547
    
548
    // Generate sample data for fourth chart
549
    echo date('H:i:s') . ' Generate sample data for chart'.EOL;
550
    $seriesData = array('Monday' => 0.1, 'Tuesday' => 0.33333, 'Wednesday' => 0.4444, 'Thursday' => 0.5, 'Friday' => 0.4666, 'Saturday' => 0.3666, 'Sunday' => 0.1666);
551
    
552
    // Create a scatter chart (that should be inserted in a shape)
553
    echo date('H:i:s') . ' Create a scatter chart (that should be inserted in a chart shape)'.EOL;
554
    $lineChart = new Scatter();
555
    $series = new Series('Downloads', $seriesData);
556
    $series->setShowSeriesName(true);
557
    $series->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_DASH);
558
    $series->getMarker()->setSize(10);
559
    $lineChart->addSeries($series);
560
    
561
    // Create a shape (chart)
562
    echo date('H:i:s') . ' Create a shape (chart)'.EOL;
563
    $shape = $currentSlide->createChartShape();
564
    $shape->setName('PHPPresentation Daily Download Distribution')
565
        ->setResizeProportional(false)
566
        ->setHeight(550)
567
        ->setWidth(700)
568
        ->setOffsetX(120)
569
        ->setOffsetY(80);
570
    $shape->setShadow($oShadow);
571
    $shape->setFill($oFill);
572
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
573
    $shape->getTitle()->setText('PHPPresentation Daily Downloads');
574
    $shape->getTitle()->getFont()->setItalic(true);
575
    $shape->getPlotArea()->setType($lineChart);
576
    $shape->getView3D()->setRotationX(30);
577
    $shape->getView3D()->setPerspective(30);
578
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
579
    $shape->getLegend()->getFont()->setItalic(true);
580
}
581
582
// Create new PHPPresentation object
583
echo date('H:i:s') . ' Create new PHPPresentation object'.EOL;
584
$objPHPPresentation = new PhpPresentation();
585
586
// Set properties
587
echo date('H:i:s') . ' Set properties'.EOL;
588
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
589
                                  ->setLastModifiedBy('PHPPresentation Team')
590
                                  ->setTitle('Sample 07 Title')
591
                                  ->setSubject('Sample 07 Subject')
592
                                  ->setDescription('Sample 07 Description')
593
                                  ->setKeywords('office 2007 openxml libreoffice odt php')
594
                                  ->setCategory('Sample Category');
595
596
// Remove first slide
597
echo date('H:i:s') . ' Remove first slide'.EOL;
598
$objPHPPresentation->removeSlideByIndex(0);
599
600
// Set Style
601
$oFill = new Fill();
602
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
603
604
$oShadow = new Shadow();
605
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);
606
607
fnSlide_Area($objPHPPresentation);
608
609
fnSlide_Bar($objPHPPresentation);
610
611
fnSlide_BarStacked($objPHPPresentation);
612
613
fnSlide_BarPercentStacked($objPHPPresentation);
614
615
fnSlide_BarHorizontal($objPHPPresentation);
616
617
fnSlide_Bar3D($objPHPPresentation);
618
619
fnSlide_Bar3DHorizontal($objPHPPresentation);
620
621
fnSlide_Doughnut($objPHPPresentation);
622
623
fnSlide_Pie3D($objPHPPresentation);
624
625
fnSlide_Pie($objPHPPresentation);
626
627
fnSlide_Scatter($objPHPPresentation);
628
629
// Save file
630
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
631
if (!CLI) {
632
    include_once 'Sample_Footer.php';
633
}
634