ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
33chartcreate-area.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 
100 // Set the series in the plot area
102 // Set the chart legend
104 
105 $title = new PHPExcel_Chart_Title('Test %age-Stacked Area Chart');
106 $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
107 
108 
109 // Create the chart
111  'chart1', // name
112  $title, // title
113  $legend, // legend
114  $plotArea, // plotArea
115  true, // plotVisibleOnly
116  0, // displayBlanksAs
117  NULL, // xAxisLabel
118  $yAxisLabel // yAxisLabel
119 );
120 
121 // Set the position where the chart should appear in the worksheet
122 $chart->setTopLeftPosition('A7');
123 $chart->setBottomRightPosition('H20');
124 
125 // Add the chart to the worksheet
126 $objWorksheet->addChart($chart);
127 
128 
129 // Save Excel 2007 file
130 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
132 $objWriter->setIncludeCharts(TRUE);
133 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
134 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
135 
136 
137 // Echo memory peak usage
138 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
139 
140 // Echo done
141 echo date('H:i:s') , " Done writing file" , EOL;
142 echo 'File has been created in ' , getcwd() , EOL;
$xAxisTickValues
$dataSeriesLabels
Resolve range
$objPHPExcel
PHPExcel.
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132
$dataSeriesValues
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())
const POSITION_TOPRIGHT
Definition: Legend.php:50
Create styles array
The data for the language used.
const EOL