ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
33chartcreate-pie.php
Go to the documentation of this file.
1<?php
2
4error_reporting(E_ALL);
5ini_set('display_errors', TRUE);
6ini_set('display_startup_errors', TRUE);
7date_default_timezone_set('Europe/London');
8
9define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
10
11date_default_timezone_set('Europe/London');
12
40require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
41
42
44$objWorksheet = $objPHPExcel->getActiveSheet();
45$objWorksheet->fromArray(
46 array(
47 array('', 2010, 2011, 2012),
48 array('Q1', 12, 15, 21),
49 array('Q2', 56, 73, 86),
50 array('Q3', 52, 61, 69),
51 array('Q4', 30, 32, 0),
52 )
53);
54
55
56// Set the Labels for each data series we want to plot
57// Datatype
58// Cell reference for data
59// Format Code
60// Number of datapoints in series
61// Data values
62// Data Marker
64 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011
65);
66// Set the X-Axis Labels
67// Datatype
68// Cell reference for data
69// Format Code
70// Number of datapoints in series
71// Data values
72// Data Marker
74 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
75);
76// Set the Data values for each data series we want to plot
77// Datatype
78// Cell reference for data
79// Format Code
80// Number of datapoints in series
81// Data values
82// Data Marker
84 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
85);
86
87// Build the dataseries
90 NULL, // plotGrouping (Pie charts don't have any grouping)
91 range(0, count($dataSeriesValues1)-1), // plotOrder
92 $dataSeriesLabels1, // plotLabel
93 $xAxisTickValues1, // plotCategory
94 $dataSeriesValues1 // plotValues
95);
96
97// Set up a layout object for the Pie chart
99$layout1->setShowVal(TRUE);
100$layout1->setShowPercent(TRUE);
101
102// Set the series in the plot area
104// Set the chart legend
106
107$title1 = new PHPExcel_Chart_Title('Test Pie Chart');
108
109
110// Create the chart
112 'chart1', // name
113 $title1, // title
114 $legend1, // legend
115 $plotArea1, // plotArea
116 true, // plotVisibleOnly
117 0, // displayBlanksAs
118 NULL, // xAxisLabel
119 NULL // yAxisLabel - Pie charts don't have a Y-Axis
120);
121
122// Set the position where the chart should appear in the worksheet
123$chart1->setTopLeftPosition('A7');
124$chart1->setBottomRightPosition('H20');
125
126// Add the chart to the worksheet
127$objWorksheet->addChart($chart1);
128
129
130// Set the Labels for each data series we want to plot
131// Datatype
132// Cell reference for data
133// Format Code
134// Number of datapoints in series
135// Data values
136// Data Marker
138 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011
139);
140// Set the X-Axis Labels
141// Datatype
142// Cell reference for data
143// Format Code
144// Number of datapoints in series
145// Data values
146// Data Marker
148 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
149);
150// Set the Data values for each data series we want to plot
151// Datatype
152// Cell reference for data
153// Format Code
154// Number of datapoints in series
155// Data values
156// Data Marker
158 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
159);
160
161// Build the dataseries
164 NULL, // plotGrouping (Donut charts don't have any grouping)
165 range(0, count($dataSeriesValues2)-1), // plotOrder
166 $dataSeriesLabels2, // plotLabel
167 $xAxisTickValues2, // plotCategory
168 $dataSeriesValues2 // plotValues
169);
170
171// Set up a layout object for the Pie chart
173$layout2->setShowVal(TRUE);
174$layout2->setShowCatName(TRUE);
175
176// Set the series in the plot area
178
179$title2 = new PHPExcel_Chart_Title('Test Donut Chart');
180
181
182// Create the chart
184 'chart2', // name
185 $title2, // title
186 NULL, // legend
187 $plotArea2, // plotArea
188 true, // plotVisibleOnly
189 0, // displayBlanksAs
190 NULL, // xAxisLabel
191 NULL // yAxisLabel - Like Pie charts, Donut charts don't have a Y-Axis
192);
193
194// Set the position where the chart should appear in the worksheet
195$chart2->setTopLeftPosition('I7');
196$chart2->setBottomRightPosition('P20');
197
198// Add the chart to the worksheet
199$objWorksheet->addChart($chart2);
200
201
202// Save Excel 2007 file
203echo date('H:i:s') , " Write to Excel2007 format" , EOL;
205$objWriter->setIncludeCharts(TRUE);
206$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
207echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
208
209
210// Echo memory peak usage
211echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
212
213// Echo done
214echo date('H:i:s') , " Done writing file" , EOL;
215echo 'File has been created in ' , getcwd() , EOL;
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$xAxisTickValues2
memory_get_peak_usage(true)/1024/1024)
const EOL
$dataSeriesValues2
$dataSeriesValues1
$dataSeriesLabels2
$dataSeriesLabels1
$objWorksheet
$objPHPExcel
PHPExcel.
$xAxisTickValues1
An exception for terminatinating execution or to throw for unit testing.
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132