ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
33chartcreate-multiple-charts.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!$B$1', NULL, 1), // 2010
65 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011
66 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012
67);
68// Set the X-Axis Labels
69// Datatype
70// Cell reference for data
71// Format Code
72// Number of datapoints in series
73// Data values
74// Data Marker
76 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
77);
78// Set the Data values for each data series we want to plot
79// Datatype
80// Cell reference for data
81// Format Code
82// Number of datapoints in series
83// Data values
84// Data Marker
86 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4),
87 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
88 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4),
89);
90
91// Build the dataseries
95 range(0, count($dataSeriesValues1)-1), // plotOrder
96 $dataSeriesLabels1, // plotLabel
97 $xAxisTickValues1, // plotCategory
98 $dataSeriesValues1 // plotValues
99);
100
101// Set the series in the plot area
103// Set the chart legend
105
106$title1 = new PHPExcel_Chart_Title('Test %age-Stacked Area 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 $yAxisLabel1 // yAxisLabel
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!$B$1', NULL, 1), // 2010
139 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011
140 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012
141);
142// Set the X-Axis Labels
143// Datatype
144// Cell reference for data
145// Format Code
146// Number of datapoints in series
147// Data values
148// Data Marker
150 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
151);
152// Set the Data values for each data series we want to plot
153// Datatype
154// Cell reference for data
155// Format Code
156// Number of datapoints in series
157// Data values
158// Data Marker
160 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4),
161 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
162 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4),
163);
164
165// Build the dataseries
169 range(0, count($dataSeriesValues2)-1), // plotOrder
170 $dataSeriesLabels2, // plotLabel
171 $xAxisTickValues2, // plotCategory
172 $dataSeriesValues2 // plotValues
173);
174// Set additional dataseries parameters
175// Make it a vertical column rather than a horizontal bar graph
177
178// Set the series in the plot area
180// Set the chart legend
182
183$title2 = new PHPExcel_Chart_Title('Test Column Chart');
185
186
187// Create the chart
189 'chart2', // name
190 $title2, // title
191 $legend2, // legend
192 $plotArea2, // plotArea
193 true, // plotVisibleOnly
194 0, // displayBlanksAs
195 NULL, // xAxisLabel
196 $yAxisLabel2 // yAxisLabel
197);
198
199// Set the position where the chart should appear in the worksheet
200$chart2->setTopLeftPosition('I7');
201$chart2->setBottomRightPosition('P20');
202
203// Add the chart to the worksheet
204$objWorksheet->addChart($chart2);
205
206
207// Save Excel 2007 file
208echo date('H:i:s') , " Write to Excel2007 format" , EOL;
210$objWriter->setIncludeCharts(TRUE);
211$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
212echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
213
214
215// Echo memory peak usage
216echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
217
218// Echo done
219echo date('H:i:s') , " Done writing file" , EOL;
220echo 'File has been created in ' , getcwd() , EOL;
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
memory_get_peak_usage(true)/1024/1024)
$objPHPExcel
PHPExcel.
An exception for terminatinating execution or to throw for unit testing.
const POSITION_TOPRIGHT
Definition: Legend.php:50
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132