ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
33chartcreate-scatter.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
69  new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
70 );
71 // Set the Data values for each data series we want to plot
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('Number', 'Worksheet!$B$2:$B$5', NULL, 4),
80  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
81  new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4),
82 );
83 
84 // Build the dataseries
87  NULL, // plotGrouping (Scatter charts don't have any grouping)
88  range(0, count($dataSeriesValues)-1), // plotOrder
89  $dataSeriesLabels, // plotLabel
90  $xAxisTickValues, // plotCategory
91  $dataSeriesValues, // plotValues
92  NULL, // smooth line
94 );
95 
96 // Set the series in the plot area
98 // Set the chart legend
100 
101 $title = new PHPExcel_Chart_Title('Test Scatter Chart');
102 $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
103 
104 
105 // Create the chart
107  'chart1', // name
108  $title, // title
109  $legend, // legend
110  $plotArea, // plotArea
111  true, // plotVisibleOnly
112  0, // displayBlanksAs
113  NULL, // xAxisLabel
114  $yAxisLabel // yAxisLabel
115 );
116 
117 // Set the position where the chart should appear in the worksheet
118 $chart->setTopLeftPosition('A7');
119 $chart->setBottomRightPosition('H20');
120 
121 // Add the chart to the worksheet
122 $objWorksheet->addChart($chart);
123 
124 
125 // Save Excel 2007 file
126 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
128 $objWriter->setIncludeCharts(TRUE);
129 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
130 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
131 
132 
133 // Echo memory peak usage
134 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
135 
136 // Echo done
137 echo date('H:i:s') , " Done writing file" , EOL;
138 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())
const POSITION_TOPRIGHT
Definition: Legend.php:50
Create styles array
The data for the language used.
$objPHPExcel
PHPExcel.