ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
33chartcreate-stock.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('Counts', 'Max', 'Min', 'Min Threshold', 'Max Threshold' ),
48  array(10, 10, 5, 0, 50 ),
49  array(30, 20, 10, 0, 50 ),
50  array(20, 30, 15, 0, 50 ),
51  array(40, 10, 0, 0, 50 ),
52  array(100, 40, 5, 0, 50 ),
53  ), null, 'A1', true
54 );
55 $objWorksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
56 
57 
58 // Set the Labels for each data series we want to plot
59 // Datatype
60 // Cell reference for data
61 // Format Code
62 // Number of datapoints in series
63 // Data values
64 // Data Marker
66  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), //Max / Open
67  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), //Min / Close
68  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), //Min Threshold / Min
69  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', NULL, 1), //Max Threshold / Max
70 );
71 // Set the X-Axis Labels
72 // Datatype
73 // Cell reference for data
74 // Format Code
75 // Number of datapoints in series
76 // Data values
77 // Data Marker
79  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$6', NULL, 5), // Counts
80 );
81 // Set the Data values for each data series we want to plot
82 // Datatype
83 // Cell reference for data
84 // Format Code
85 // Number of datapoints in series
86 // Data values
87 // Data Marker
89  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$6', NULL, 5),
90  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$6', NULL, 5),
91  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$6', NULL, 5),
92  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$6', NULL, 5),
93 );
94 
95 // Build the dataseries
98  null, // plotGrouping - if we set this to not null, then xlsx throws error
99  range(0, count($dataSeriesValues)-1), // plotOrder
100  $dataSeriesLabels, // plotLabel
101  $xAxisTickValues, // plotCategory
102  $dataSeriesValues // plotValues
103 );
104 
105 // Set the series in the plot area
107 // Set the chart legend
109 
110 $title = new PHPExcel_Chart_Title('Test Stock Chart');
113 
114 // Create the chart
116  'stock-chart', // name
117  $title, // title
118  $legend, // legend
119  $plotArea, // plotArea
120  true, // plotVisibleOnly
121  0, // displayBlanksAs
122  $xAxisLabel, // xAxisLabel
123  $yAxisLabel // yAxisLabel
124 );
125 
126 // Set the position where the chart should appear in the worksheet
127 $chart->setTopLeftPosition('A7');
128 $chart->setBottomRightPosition('H20');
129 
130 // Add the chart to the worksheet
131 $objWorksheet->addChart($chart);
132 
133 
134 // Save Excel 2007 file
135 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
137 $objWriter->setIncludeCharts(TRUE);
138 $filename = str_replace('.php', '.xlsx', __FILE__);
139 if(file_exists($filename)) {
140  unlink($filename);
141 }
142 $objWriter->save($filename);
143 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
144 
145 
146 // Echo memory peak usage
147 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
148 
149 // Echo done
150 echo date('H:i:s') , " Done writing file" , EOL;
151 echo 'File has been created in ' , getcwd() , EOL;
const EOL
Resolve range
$dataSeriesValues
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.
$xAxisTickValues
$objPHPExcel
PHPExcel.
$dataSeriesLabels