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-pie.php

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

216 lines 6.4 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('', 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
63 $dataSeriesLabels1 = array(
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
73 $xAxisTickValues1 = array(
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
83 $dataSeriesValues1 = array(
84 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
85 );
86
87 // Build the dataseries
88 $series1 = new PHPExcel_Chart_DataSeries(
89 PHPExcel_Chart_DataSeries::TYPE_PIECHART, // plotType
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
98 $layout1 = new PHPExcel_Chart_Layout();
99 $layout1->setShowVal(TRUE);
100 $layout1->setShowPercent(TRUE);
101
102 // Set the series in the plot area
103 $plotArea1 = new PHPExcel_Chart_PlotArea($layout1, array($series1));
104 // Set the chart legend
105 $legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
106
107 $title1 = new PHPExcel_Chart_Title('Test Pie Chart');
108
109
110 // Create the chart
111 $chart1 = new PHPExcel_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
137 $dataSeriesLabels2 = array(
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
147 $xAxisTickValues2 = array(
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
157 $dataSeriesValues2 = array(
158 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
159 );
160
161 // Build the dataseries
162 $series2 = new PHPExcel_Chart_DataSeries(
163 PHPExcel_Chart_DataSeries::TYPE_DONUTCHART, // plotType
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
172 $layout2 = new PHPExcel_Chart_Layout();
173 $layout2->setShowVal(TRUE);
174 $layout2->setShowCatName(TRUE);
175
176 // Set the series in the plot area
177 $plotArea2 = new PHPExcel_Chart_PlotArea($layout2, array($series2));
178
179 $title2 = new PHPExcel_Chart_Title('Test Donut Chart');
180
181
182 // Create the chart
183 $chart2 = new PHPExcel_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
203 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
204 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
205 $objWriter->setIncludeCharts(TRUE);
206 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
207 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
208
209
210 // Echo memory peak usage
211 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
212
213 // Echo done
214 echo date('H:i:s') , " Done writing file" , EOL;
215 echo 'File has been created in ' , getcwd() , EOL;
216