ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
33chartcreate-composite.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('', 'Rainfall (mm)', 'Temperature (°F)', 'Humidity (%)'),
48 array('Jan', 78, 52, 61),
49 array('Feb', 64, 54, 62),
50 array('Mar', 62, 57, 63),
51 array('Apr', 21, 62, 59),
52 array('May', 11, 75, 60),
53 array('Jun', 1, 75, 57),
54 array('Jul', 1, 79, 56),
55 array('Aug', 1, 79, 59),
56 array('Sep', 10, 75, 60),
57 array('Oct', 40, 68, 63),
58 array('Nov', 69, 62, 64),
59 array('Dec', 89, 57, 66),
60 )
61);
62
63
64// Set the Labels for each data series we want to plot
65// Datatype
66// Cell reference for data
67// Format Code
68// Number of datapoints in series
69// Data values
70// Data Marker
72 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // Temperature
73);
75 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // Rainfall
76);
78 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // Humidity
79);
80
81// Set the X-Axis Labels
82// Datatype
83// Cell reference for data
84// Format Code
85// Number of datapoints in series
86// Data values
87// Data Marker
89 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$13', NULL, 12), // Jan to Dec
90);
91
92
93// Set the Data values for each data series we want to plot
94// Datatype
95// Cell reference for data
96// Format Code
97// Number of datapoints in series
98// Data values
99// Data Marker
101 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', NULL, 12),
102);
103
104// Build the dataseries
108 range(0, count($dataSeriesValues1)-1), // plotOrder
109 $dataSeriesLabels1, // plotLabel
110 $xAxisTickValues, // plotCategory
111 $dataSeriesValues1 // plotValues
112);
113// Set additional dataseries parameters
114// Make it a vertical column rather than a horizontal bar graph
116
117
118// Set the Data values for each data series we want to plot
119// Datatype
120// Cell reference for data
121// Format Code
122// Number of datapoints in series
123// Data values
124// Data Marker
126 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12),
127);
128
129// Build the dataseries
133 range(0, count($dataSeriesValues2)-1), // plotOrder
134 $dataSeriesLabels2, // plotLabel
135 NULL, // plotCategory
136 $dataSeriesValues2 // plotValues
137);
138
139
140// Set the Data values for each data series we want to plot
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('Number', 'Worksheet!$D$2:$D$13', NULL, 12),
149);
150
151// Build the dataseries
155 range(0, count($dataSeriesValues2)-1), // plotOrder
156 $dataSeriesLabels3, // plotLabel
157 NULL, // plotCategory
158 $dataSeriesValues3 // plotValues
159);
160
161
162// Set the series in the plot area
164// Set the chart legend
166
167$title = new PHPExcel_Chart_Title('Average Weather Chart for Crete');
168
169
170// Create the chart
172 'chart1', // name
173 $title, // title
174 $legend, // legend
175 $plotArea, // plotArea
176 true, // plotVisibleOnly
177 0, // displayBlanksAs
178 NULL, // xAxisLabel
179 NULL // yAxisLabel
180);
181
182// Set the position where the chart should appear in the worksheet
183$chart->setTopLeftPosition('F2');
184$chart->setBottomRightPosition('O16');
185
186// Add the chart to the worksheet
187$objWorksheet->addChart($chart);
188
189
190// Save Excel 2007 file
191echo date('H:i:s') , " Write to Excel2007 format" , EOL;
193$objWriter->setIncludeCharts(TRUE);
194$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
195echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
196
197
198// Echo memory peak usage
199echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
200
201// Echo done
202echo date('H:i:s') , " Done writing file" , EOL;
203echo '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.
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132