ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
33chartcreate-bar-stacked.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('', 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
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
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
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
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 horizontal bar rather than a vertical column graph
102 
103 // Set the series in the plot area
105 // Set the chart legend
107 
108 $title = new PHPExcel_Chart_Title('Test Chart');
109 $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
110 
111 
112 // Create the 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;
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;
Resolve range
$objPHPExcel
PHPExcel.
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.