PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.2.0
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpexcel / Examples / 33chartcreate-composite.php

33chartcreate-composite.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 2.2.0, at vendor/phpoffice/phpexcel/Examples/33chartcreate-composite.php

204 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /** Error reporting */
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');
8
9 define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
10
11 date_default_timezone_set('Europe/London');
12
13 /**
14 * PHPExcel
15 *
16 * Copyright (C) 2006 - 2014 PHPExcel
17 *
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.
22 *
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.
27 *
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
31 *
32 * @category PHPExcel
33 * @package PHPExcel
34 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
36 * @version ##VERSION##, ##DATE##
37 */
38
39 /** PHPExcel */
40 require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
41
42
43 $objPHPExcel = new PHPExcel();
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
71 $dataSeriesLabels1 = array(
72 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // Temperature
73 );
74 $dataSeriesLabels2 = array(
75 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // Rainfall
76 );
77 $dataSeriesLabels3 = array(
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
88 $xAxisTickValues = array(
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
100 $dataSeriesValues1 = array(
101 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', NULL, 12),
102 );
103
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
112 );
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);
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
125 $dataSeriesValues2 = array(
126 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12),
127 );
128
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
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
147 $dataSeriesValues3 = array(
148 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', NULL, 12),
149 );
150
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
159 );
160
161
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);
166
167 $title = new PHPExcel_Chart_Title('Average Weather Chart for Crete');
168
169
170 // Create the chart
171 $chart = new PHPExcel_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
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;
196
197
198 // Echo memory peak usage
199 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
200
201 // Echo done
202 echo date('H:i:s') , " Done writing file" , EOL;
203 echo 'File has been created in ' , getcwd() , EOL;
204