ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
33chartcreate-column-2.php
Go to the documentation of this file.
1 <?php
2 
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 
40 require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
41 
42 
44 $objWorksheet = $objPHPExcel->getActiveSheet();
45 $objWorksheet->fromArray(
46  array(
47  array('', '', 'Budget', 'Forecast', 'Actual'),
48  array('2010', 'Q1', 47, 44, 43 ),
49  array('', 'Q2', 56, 53, 50 ),
50  array('', 'Q3', 52, 46, 45 ),
51  array('', 'Q4', 45, 40, 40 ),
52  array('2011', 'Q1', 51, 42, 46 ),
53  array('', 'Q2', 53, 58, 56 ),
54  array('', 'Q3', 64, 66, 69 ),
55  array('', 'Q4', 54, 55, 56 ),
56  array('2012', 'Q1', 49, 52, 58 ),
57  array('', 'Q2', 68, 73, 86 ),
58  array('', 'Q3', 72, 78, 0 ),
59  array('', 'Q4', 50, 60, 0 ),
60  )
61 );
62 
63 // Set the Labels for each data series we want to plot
64 // Datatype
65 // Cell reference for data
66 // Format Code
67 // Number of datapoints in series
68 // Data values
69 // Data Marker
71  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 'Budget'
72  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 'Forecast'
73  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', NULL, 1), // 'Actual'
74 );
75 // Set the X-Axis Labels
76 // Datatype
77 // Cell reference for data
78 // Format Code
79 // Number of datapoints in series
80 // Data values
81 // Data Marker
83  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$B$13', NULL, 12), // Q1 to Q4 for 2010 to 2012
84 );
85 // Set the Data values for each data series we want to plot
86 // Datatype
87 // Cell reference for data
88 // Format Code
89 // Number of datapoints in series
90 // Data values
91 // Data Marker
93  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12),
94  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', NULL, 12),
95  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$13', NULL, 12),
96 );
97 
98 // Build the dataseries
102  range(0, count($dataSeriesValues)-1), // plotOrder
103  $dataSeriesLabels, // plotLabel
104  $xAxisTickValues, // plotCategory
105  $dataSeriesValues // plotValues
106 );
107 // Set additional dataseries parameters
108 // Make it a vertical column rather than a horizontal bar graph
110 
111 // Set the series in the plot area
113 // Set the chart legend
115 
116 $title = new PHPExcel_Chart_Title('Test Grouped Column Chart');
117 $xAxisLabel = new PHPExcel_Chart_Title('Financial Period');
118 $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
119 
120 
121 // Create the chart
123  'chart1', // name
124  $title, // title
125  $legend, // legend
126  $plotArea, // plotArea
127  true, // plotVisibleOnly
128  0, // displayBlanksAs
129  $xAxisLabel, // xAxisLabel
130  $yAxisLabel // yAxisLabel
131 );
132 
133 // Set the position where the chart should appear in the worksheet
134 $chart->setTopLeftPosition('G2');
135 $chart->setBottomRightPosition('P20');
136 
137 // Add the chart to the worksheet
138 $objWorksheet->addChart($chart);
139 
140 
141 // Save Excel 2007 file
142 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
144 $objWriter->setIncludeCharts(TRUE);
145 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
146 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
147 
148 
149 // Echo memory peak usage
150 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
151 
152 // Echo done
153 echo date('H:i:s') , " Done writing file" , EOL;
154 echo 'File has been created in ' , getcwd() , EOL;
Resolve range
const EOL
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
$objPHPExcel
PHPExcel.