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

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

146 lines 4.7 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 // Set the Labels for each data series we want to plot
56 // Datatype
57 // Cell reference for data
58 // Format Code
59 // Number of datapoints in series
60 // Data values
61 // Data Marker
62 $dataSeriesLabels = array(
63 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010
64 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011
65 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012
66 );
67 // Set the X-Axis Labels
68 // Datatype
69 // Cell reference for data
70 // Format Code
71 // Number of datapoints in series
72 // Data values
73 // Data Marker
74 $xAxisTickValues = array(
75 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
76 );
77 // Set the Data values for each data series we want to plot
78 // Datatype
79 // Cell reference for data
80 // Format Code
81 // Number of datapoints in series
82 // Data values
83 // Data Marker
84 $dataSeriesValues = array(
85 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4),
86 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
87 new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4),
88 );
89
90 // Build the dataseries
91 $series = new PHPExcel_Chart_DataSeries(
92 PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
93 PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
94 range(0, count($dataSeriesValues)-1), // plotOrder
95 $dataSeriesLabels, // plotLabel
96 $xAxisTickValues, // plotCategory
97 $dataSeriesValues // plotValues
98 );
99 // Set additional dataseries parameters
100 // Make it a vertical column rather than a horizontal bar graph
101 $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
102
103 // Set the series in the plot area
104 $plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series));
105 // Set the chart legend
106 $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
107
108 $title = new PHPExcel_Chart_Title('Test Column Chart');
109 $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
110
111
112 // Create the chart
113 $chart = new PHPExcel_Chart(
114 'chart1', // name
115 $title, // title
116 $legend, // legend
117 $plotArea, // plotArea
118 true, // plotVisibleOnly
119 0, // displayBlanksAs
120 NULL, // xAxisLabel
121 $yAxisLabel // yAxisLabel
122 );
123
124 // Set the position where the chart should appear in the worksheet
125 $chart->setTopLeftPosition('A7');
126 $chart->setBottomRightPosition('H20');
127
128 // Add the chart to the worksheet
129 $objWorksheet->addChart($chart);
130
131
132 // Save Excel 2007 file
133 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
134 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
135 $objWriter->setIncludeCharts(TRUE);
136 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
137 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
138
139
140 // Echo memory peak usage
141 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
142
143 // Echo done
144 echo date('H:i:s') , " Done writing file" , EOL;
145 echo 'File has been created in ' , getcwd() , EOL;
146