4 error_reporting(E_ALL);
5 ini_set('display_errors', TRUE);
6 ini_set('display_startup_errors', TRUE);
7 date_default_timezone_set('Europe/London');
9 define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
11 date_default_timezone_set('Europe/London');
16 * Copyright (c) 2006 - 2015 PHPExcel
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with this library; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
35 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
36 * @version ##VERSION##, ##DATE##
40 require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
43 $objPHPExcel = new PHPExcel();
44 $objWorksheet = $objPHPExcel->getActiveSheet();
45 $objWorksheet->fromArray(
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),
64 // Set the Labels for each data series we want to plot
66 // Cell reference for data
68 // Number of datapoints in series
71 $dataSeriesLabels1 = array(
72 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // Temperature
74 $dataSeriesLabels2 = array(
75 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // Rainfall
77 $dataSeriesLabels3 = array(
78 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // Humidity
81 // Set the X-Axis Labels
83 // Cell reference for data
85 // Number of datapoints in series
88 $xAxisTickValues = array(
89 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$13', NULL, 12), // Jan to Dec
93 // Set the Data values for each data series we want to plot
95 // Cell reference for data
97 // Number of datapoints in series
100 $dataSeriesValues1 = array(
101 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', NULL, 12),
104 // Build the dataseries
105 $series1 = new PHPExcel_Chart_DataSeries(
106 PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
107 PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
108 range(0, count($dataSeriesValues1)-1), // plotOrder
109 $dataSeriesLabels1, // plotLabel
110 $xAxisTickValues, // plotCategory
111 $dataSeriesValues1 // plotValues
113 // Set additional dataseries parameters
114 // Make it a vertical column rather than a horizontal bar graph
115 $series1->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
118 // Set the Data values for each data series we want to plot
120 // Cell reference for data
122 // Number of datapoints in series
125 $dataSeriesValues2 = array(
126 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12),
129 // Build the dataseries
130 $series2 = new PHPExcel_Chart_DataSeries(
131 PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
132 PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
133 range(0, count($dataSeriesValues2)-1), // plotOrder
134 $dataSeriesLabels2, // plotLabel
135 NULL, // plotCategory
136 $dataSeriesValues2 // plotValues
140 // Set the Data values for each data series we want to plot
142 // Cell reference for data
144 // Number of datapoints in series
147 $dataSeriesValues3 = array(
148 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', NULL, 12),
151 // Build the dataseries
152 $series3 = new PHPExcel_Chart_DataSeries(
153 PHPExcel_Chart_DataSeries::TYPE_AREACHART, // plotType
154 PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
155 range(0, count($dataSeriesValues2)-1), // plotOrder
156 $dataSeriesLabels3, // plotLabel
157 NULL, // plotCategory
158 $dataSeriesValues3 // plotValues
162 // Set the series in the plot area
163 $plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series1, $series2, $series3));
164 // Set the chart legend
165 $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
167 $title = new PHPExcel_Chart_Title('Average Weather Chart for Crete');
171 $chart = new PHPExcel_Chart(
175 $plotArea, // plotArea
176 true, // plotVisibleOnly
177 0, // displayBlanksAs
182 // Set the position where the chart should appear in the worksheet
183 $chart->setTopLeftPosition('F2');
184 $chart->setBottomRightPosition('O16');
186 // Add the chart to the worksheet
187 $objWorksheet->addChart($chart);
190 // Save Excel 2007 file
191 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
192 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
193 $objWriter->setIncludeCharts(TRUE);
194 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
195 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
198 // Echo memory peak usage
199 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
202 echo date('H:i:s') , " Done writing file" , EOL;
203 echo 'File has been created in ' , getcwd() , EOL;