2390 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PHPExcel
|
|
|
4 |
*
|
|
|
5 |
* Copyright (c) 2006 - 2013 PHPExcel
|
|
|
6 |
*
|
|
|
7 |
* This library is free software; you can redistribute it and/or
|
|
|
8 |
* modify it under the terms of the GNU Lesser General Public
|
|
|
9 |
* License as published by the Free Software Foundation; either
|
|
|
10 |
* version 2.1 of the License, or (at your option) any later version.
|
|
|
11 |
*
|
|
|
12 |
* This library is distributed in the hope that it will be useful,
|
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
15 |
* Lesser General Public License for more details.
|
|
|
16 |
*
|
|
|
17 |
* You should have received a copy of the GNU Lesser General Public
|
|
|
18 |
* License along with this library; if not, write to the Free Software
|
|
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
20 |
*
|
|
|
21 |
* @category PHPExcel
|
|
|
22 |
* @package PHPExcel_Writer_Excel2007
|
|
|
23 |
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
|
|
24 |
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
25 |
* @version ##VERSION##, ##DATE##
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* PHPExcel_Writer_Excel2007_Chart
|
|
|
31 |
*
|
|
|
32 |
* @category PHPExcel
|
|
|
33 |
* @package PHPExcel_Writer_Excel2007
|
|
|
34 |
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
|
|
35 |
*/
|
|
|
36 |
class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPart
|
|
|
37 |
{
|
|
|
38 |
/**
|
|
|
39 |
* Write charts to XML format
|
|
|
40 |
*
|
|
|
41 |
* @param PHPExcel_Chart $pChart
|
|
|
42 |
* @return string XML Output
|
|
|
43 |
* @throws PHPExcel_Writer_Exception
|
|
|
44 |
*/
|
|
|
45 |
public function writeChart(PHPExcel_Chart $pChart = null)
|
|
|
46 |
{
|
|
|
47 |
// Create XML writer
|
|
|
48 |
$objWriter = null;
|
|
|
49 |
if ($this->getParentWriter()->getUseDiskCaching()) {
|
|
|
50 |
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
|
|
51 |
} else {
|
|
|
52 |
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
|
|
|
53 |
}
|
|
|
54 |
// Ensure that data series values are up-to-date before we save
|
|
|
55 |
$pChart->refresh();
|
|
|
56 |
|
|
|
57 |
// XML header
|
|
|
58 |
$objWriter->startDocument('1.0','UTF-8','yes');
|
|
|
59 |
|
|
|
60 |
// c:chartSpace
|
|
|
61 |
$objWriter->startElement('c:chartSpace');
|
|
|
62 |
$objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
|
|
|
63 |
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
|
|
|
64 |
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
|
|
|
65 |
|
|
|
66 |
$objWriter->startElement('c:date1904');
|
|
|
67 |
$objWriter->writeAttribute('val', 0);
|
|
|
68 |
$objWriter->endElement();
|
|
|
69 |
$objWriter->startElement('c:lang');
|
|
|
70 |
$objWriter->writeAttribute('val', "en-GB");
|
|
|
71 |
$objWriter->endElement();
|
|
|
72 |
$objWriter->startElement('c:roundedCorners');
|
|
|
73 |
$objWriter->writeAttribute('val', 0);
|
|
|
74 |
$objWriter->endElement();
|
|
|
75 |
|
|
|
76 |
$this->_writeAlternateContent($objWriter);
|
|
|
77 |
|
|
|
78 |
$objWriter->startElement('c:chart');
|
|
|
79 |
|
|
|
80 |
$this->_writeTitle($pChart->getTitle(), $objWriter);
|
|
|
81 |
|
|
|
82 |
$objWriter->startElement('c:autoTitleDeleted');
|
|
|
83 |
$objWriter->writeAttribute('val', 0);
|
|
|
84 |
$objWriter->endElement();
|
|
|
85 |
|
|
|
86 |
$this->_writePlotArea($pChart->getPlotArea(),
|
|
|
87 |
$pChart->getXAxisLabel(),
|
|
|
88 |
$pChart->getYAxisLabel(),
|
|
|
89 |
$objWriter,
|
|
|
90 |
$pChart->getWorksheet()
|
|
|
91 |
);
|
|
|
92 |
|
|
|
93 |
$this->_writeLegend($pChart->getLegend(), $objWriter);
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
$objWriter->startElement('c:plotVisOnly');
|
|
|
97 |
$objWriter->writeAttribute('val', 1);
|
|
|
98 |
$objWriter->endElement();
|
|
|
99 |
|
|
|
100 |
$objWriter->startElement('c:dispBlanksAs');
|
|
|
101 |
$objWriter->writeAttribute('val', "gap");
|
|
|
102 |
$objWriter->endElement();
|
|
|
103 |
|
|
|
104 |
$objWriter->startElement('c:showDLblsOverMax');
|
|
|
105 |
$objWriter->writeAttribute('val', 0);
|
|
|
106 |
$objWriter->endElement();
|
|
|
107 |
|
|
|
108 |
$objWriter->endElement();
|
|
|
109 |
|
|
|
110 |
$this->_writePrintSettings($objWriter);
|
|
|
111 |
|
|
|
112 |
$objWriter->endElement();
|
|
|
113 |
|
|
|
114 |
// Return
|
|
|
115 |
return $objWriter->getData();
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/**
|
|
|
119 |
* Write Chart Title
|
|
|
120 |
*
|
|
|
121 |
* @param PHPExcel_Chart_Title $title
|
|
|
122 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
123 |
* @throws PHPExcel_Writer_Exception
|
|
|
124 |
*/
|
|
|
125 |
private function _writeTitle(PHPExcel_Chart_Title $title = null, $objWriter)
|
|
|
126 |
{
|
|
|
127 |
if (is_null($title)) {
|
|
|
128 |
return;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
$objWriter->startElement('c:title');
|
|
|
132 |
$objWriter->startElement('c:tx');
|
|
|
133 |
$objWriter->startElement('c:rich');
|
|
|
134 |
|
|
|
135 |
$objWriter->startElement('a:bodyPr');
|
|
|
136 |
$objWriter->endElement();
|
|
|
137 |
|
|
|
138 |
$objWriter->startElement('a:lstStyle');
|
|
|
139 |
$objWriter->endElement();
|
|
|
140 |
|
|
|
141 |
$objWriter->startElement('a:p');
|
|
|
142 |
|
|
|
143 |
$caption = $title->getCaption();
|
|
|
144 |
if ((is_array($caption)) && (count($caption) > 0))
|
|
|
145 |
$caption = $caption[0];
|
|
|
146 |
$this->getParentWriter()->getWriterPart('stringtable')->writeRichTextForCharts($objWriter, $caption, 'a');
|
|
|
147 |
|
|
|
148 |
$objWriter->endElement();
|
|
|
149 |
$objWriter->endElement();
|
|
|
150 |
$objWriter->endElement();
|
|
|
151 |
|
|
|
152 |
$layout = $title->getLayout();
|
|
|
153 |
$this->_writeLayout($layout, $objWriter);
|
|
|
154 |
|
|
|
155 |
$objWriter->startElement('c:overlay');
|
|
|
156 |
$objWriter->writeAttribute('val', 0);
|
|
|
157 |
$objWriter->endElement();
|
|
|
158 |
|
|
|
159 |
$objWriter->endElement();
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
/**
|
|
|
163 |
* Write Chart Legend
|
|
|
164 |
*
|
|
|
165 |
* @param PHPExcel_Chart_Legend $legend
|
|
|
166 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
167 |
* @throws PHPExcel_Writer_Exception
|
|
|
168 |
*/
|
|
|
169 |
private function _writeLegend(PHPExcel_Chart_Legend $legend = null, $objWriter)
|
|
|
170 |
{
|
|
|
171 |
if (is_null($legend)) {
|
|
|
172 |
return;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
$objWriter->startElement('c:legend');
|
|
|
176 |
|
|
|
177 |
$objWriter->startElement('c:legendPos');
|
|
|
178 |
$objWriter->writeAttribute('val', $legend->getPosition());
|
|
|
179 |
$objWriter->endElement();
|
|
|
180 |
|
|
|
181 |
$layout = $legend->getLayout();
|
|
|
182 |
$this->_writeLayout($layout, $objWriter);
|
|
|
183 |
|
|
|
184 |
$objWriter->startElement('c:overlay');
|
|
|
185 |
$objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0');
|
|
|
186 |
$objWriter->endElement();
|
|
|
187 |
|
|
|
188 |
$objWriter->startElement('c:txPr');
|
|
|
189 |
$objWriter->startElement('a:bodyPr');
|
|
|
190 |
$objWriter->endElement();
|
|
|
191 |
|
|
|
192 |
$objWriter->startElement('a:lstStyle');
|
|
|
193 |
$objWriter->endElement();
|
|
|
194 |
|
|
|
195 |
$objWriter->startElement('a:p');
|
|
|
196 |
$objWriter->startElement('a:pPr');
|
|
|
197 |
$objWriter->writeAttribute('rtl', 0);
|
|
|
198 |
|
|
|
199 |
$objWriter->startElement('a:defRPr');
|
|
|
200 |
$objWriter->endElement();
|
|
|
201 |
$objWriter->endElement();
|
|
|
202 |
|
|
|
203 |
$objWriter->startElement('a:endParaRPr');
|
|
|
204 |
$objWriter->writeAttribute('lang', "en-US");
|
|
|
205 |
$objWriter->endElement();
|
|
|
206 |
|
|
|
207 |
$objWriter->endElement();
|
|
|
208 |
$objWriter->endElement();
|
|
|
209 |
|
|
|
210 |
$objWriter->endElement();
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
/**
|
|
|
214 |
* Write Chart Plot Area
|
|
|
215 |
*
|
|
|
216 |
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
217 |
* @param PHPExcel_Chart_Title $xAxisLabel
|
|
|
218 |
* @param PHPExcel_Chart_Title $yAxisLabel
|
|
|
219 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
220 |
* @throws PHPExcel_Writer_Exception
|
|
|
221 |
*/
|
|
|
222 |
private function _writePlotArea(PHPExcel_Chart_PlotArea $plotArea,
|
|
|
223 |
PHPExcel_Chart_Title $xAxisLabel = NULL,
|
|
|
224 |
PHPExcel_Chart_Title $yAxisLabel = NULL,
|
|
|
225 |
$objWriter,
|
|
|
226 |
PHPExcel_Worksheet $pSheet)
|
|
|
227 |
{
|
|
|
228 |
if (is_null($plotArea)) {
|
|
|
229 |
return;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
$id1 = $id2 = 0;
|
|
|
233 |
$this->_seriesIndex = 0;
|
|
|
234 |
$objWriter->startElement('c:plotArea');
|
|
|
235 |
|
|
|
236 |
$layout = $plotArea->getLayout();
|
|
|
237 |
|
|
|
238 |
$this->_writeLayout($layout, $objWriter);
|
|
|
239 |
|
|
|
240 |
$chartTypes = self::_getChartType($plotArea);
|
|
|
241 |
$catIsMultiLevelSeries = $valIsMultiLevelSeries = FALSE;
|
|
|
242 |
$plotGroupingType = '';
|
|
|
243 |
foreach($chartTypes as $chartType) {
|
|
|
244 |
$objWriter->startElement('c:'.$chartType);
|
|
|
245 |
|
|
|
246 |
$groupCount = $plotArea->getPlotGroupCount();
|
|
|
247 |
for($i = 0; $i < $groupCount; ++$i) {
|
|
|
248 |
$plotGroup = $plotArea->getPlotGroupByIndex($i);
|
|
|
249 |
$groupType = $plotGroup->getPlotType();
|
|
|
250 |
if ($groupType == $chartType) {
|
|
|
251 |
|
|
|
252 |
$plotStyle = $plotGroup->getPlotStyle();
|
|
|
253 |
if ($groupType === PHPExcel_Chart_DataSeries::TYPE_RADARCHART) {
|
|
|
254 |
$objWriter->startElement('c:radarStyle');
|
|
|
255 |
$objWriter->writeAttribute('val', $plotStyle );
|
|
|
256 |
$objWriter->endElement();
|
|
|
257 |
} elseif ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART) {
|
|
|
258 |
$objWriter->startElement('c:scatterStyle');
|
|
|
259 |
$objWriter->writeAttribute('val', $plotStyle );
|
|
|
260 |
$objWriter->endElement();
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
$this->_writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet);
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
$this->_writeDataLbls($objWriter, $layout);
|
|
|
268 |
|
|
|
269 |
if ($chartType === PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
|
|
|
270 |
// Line only, Line3D can't be smoothed
|
|
|
271 |
|
|
|
272 |
$objWriter->startElement('c:smooth');
|
|
|
273 |
$objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() );
|
|
|
274 |
$objWriter->endElement();
|
|
|
275 |
} elseif (($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
|
|
276 |
($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
|
|
|
277 |
|
|
|
278 |
$objWriter->startElement('c:gapWidth');
|
|
|
279 |
$objWriter->writeAttribute('val', 150 );
|
|
|
280 |
$objWriter->endElement();
|
|
|
281 |
|
|
|
282 |
if ($plotGroupingType == 'percentStacked' ||
|
|
|
283 |
$plotGroupingType == 'stacked') {
|
|
|
284 |
|
|
|
285 |
$objWriter->startElement('c:overlap');
|
|
|
286 |
$objWriter->writeAttribute('val', 100 );
|
|
|
287 |
$objWriter->endElement();
|
|
|
288 |
}
|
|
|
289 |
} elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
290 |
|
|
|
291 |
$objWriter->startElement('c:bubbleScale');
|
|
|
292 |
$objWriter->writeAttribute('val', 25 );
|
|
|
293 |
$objWriter->endElement();
|
|
|
294 |
|
|
|
295 |
$objWriter->startElement('c:showNegBubbles');
|
|
|
296 |
$objWriter->writeAttribute('val', 0 );
|
|
|
297 |
$objWriter->endElement();
|
|
|
298 |
} elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) {
|
|
|
299 |
|
|
|
300 |
$objWriter->startElement('c:hiLowLines');
|
|
|
301 |
$objWriter->endElement();
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
// Generate 2 unique numbers to use for axId values
|
|
|
305 |
// $id1 = $id2 = rand(10000000,99999999);
|
|
|
306 |
// do {
|
|
|
307 |
// $id2 = rand(10000000,99999999);
|
|
|
308 |
// } while ($id1 == $id2);
|
|
|
309 |
$id1 = '75091328';
|
|
|
310 |
$id2 = '75089408';
|
|
|
311 |
|
|
|
312 |
if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
|
|
313 |
($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
|
|
314 |
($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
|
315 |
|
|
|
316 |
$objWriter->startElement('c:axId');
|
|
|
317 |
$objWriter->writeAttribute('val', $id1 );
|
|
|
318 |
$objWriter->endElement();
|
|
|
319 |
$objWriter->startElement('c:axId');
|
|
|
320 |
$objWriter->writeAttribute('val', $id2 );
|
|
|
321 |
$objWriter->endElement();
|
|
|
322 |
} else {
|
|
|
323 |
$objWriter->startElement('c:firstSliceAng');
|
|
|
324 |
$objWriter->writeAttribute('val', 0);
|
|
|
325 |
$objWriter->endElement();
|
|
|
326 |
|
|
|
327 |
if ($chartType === PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) {
|
|
|
328 |
|
|
|
329 |
$objWriter->startElement('c:holeSize');
|
|
|
330 |
$objWriter->writeAttribute('val', 50);
|
|
|
331 |
$objWriter->endElement();
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
$objWriter->endElement();
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
|
|
339 |
($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
|
|
340 |
($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
|
341 |
|
|
|
342 |
if ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
343 |
$this->_writeValAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries);
|
|
|
344 |
} else {
|
|
|
345 |
$this->_writeCatAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries);
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
$this->_writeValAx($objWriter,$plotArea,$yAxisLabel,$chartType,$id1,$id2,$valIsMultiLevelSeries);
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
$objWriter->endElement();
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
/**
|
|
|
355 |
* Write Data Labels
|
|
|
356 |
*
|
|
|
357 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
358 |
* @param PHPExcel_Chart_Layout $chartLayout Chart layout
|
|
|
359 |
* @throws PHPExcel_Writer_Exception
|
|
|
360 |
*/
|
|
|
361 |
private function _writeDataLbls($objWriter, $chartLayout)
|
|
|
362 |
{
|
|
|
363 |
$objWriter->startElement('c:dLbls');
|
|
|
364 |
|
|
|
365 |
$objWriter->startElement('c:showLegendKey');
|
|
|
366 |
$showLegendKey = (empty($chartLayout)) ? 0 : $chartLayout->getShowLegendKey();
|
|
|
367 |
$objWriter->writeAttribute('val', ((empty($showLegendKey)) ? 0 : 1) );
|
|
|
368 |
$objWriter->endElement();
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
$objWriter->startElement('c:showVal');
|
|
|
372 |
$showVal = (empty($chartLayout)) ? 0 : $chartLayout->getShowVal();
|
|
|
373 |
$objWriter->writeAttribute('val', ((empty($showVal)) ? 0 : 1) );
|
|
|
374 |
$objWriter->endElement();
|
|
|
375 |
|
|
|
376 |
$objWriter->startElement('c:showCatName');
|
|
|
377 |
$showCatName = (empty($chartLayout)) ? 0 : $chartLayout->getShowCatName();
|
|
|
378 |
$objWriter->writeAttribute('val', ((empty($showCatName)) ? 0 : 1) );
|
|
|
379 |
$objWriter->endElement();
|
|
|
380 |
|
|
|
381 |
$objWriter->startElement('c:showSerName');
|
|
|
382 |
$showSerName = (empty($chartLayout)) ? 0 : $chartLayout->getShowSerName();
|
|
|
383 |
$objWriter->writeAttribute('val', ((empty($showSerName)) ? 0 : 1) );
|
|
|
384 |
$objWriter->endElement();
|
|
|
385 |
|
|
|
386 |
$objWriter->startElement('c:showPercent');
|
|
|
387 |
$showPercent = (empty($chartLayout)) ? 0 : $chartLayout->getShowPercent();
|
|
|
388 |
$objWriter->writeAttribute('val', ((empty($showPercent)) ? 0 : 1) );
|
|
|
389 |
$objWriter->endElement();
|
|
|
390 |
|
|
|
391 |
$objWriter->startElement('c:showBubbleSize');
|
|
|
392 |
$showBubbleSize = (empty($chartLayout)) ? 0 : $chartLayout->getShowBubbleSize();
|
|
|
393 |
$objWriter->writeAttribute('val', ((empty($showBubbleSize)) ? 0 : 1) );
|
|
|
394 |
$objWriter->endElement();
|
|
|
395 |
|
|
|
396 |
$objWriter->startElement('c:showLeaderLines');
|
|
|
397 |
$showLeaderLines = (empty($chartLayout)) ? 1 : $chartLayout->getShowLeaderLines();
|
|
|
398 |
$objWriter->writeAttribute('val', ((empty($showLeaderLines)) ? 0 : 1) );
|
|
|
399 |
$objWriter->endElement();
|
|
|
400 |
|
|
|
401 |
$objWriter->endElement();
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
/**
|
|
|
405 |
* Write Category Axis
|
|
|
406 |
*
|
|
|
407 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
408 |
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
409 |
* @param PHPExcel_Chart_Title $xAxisLabel
|
|
|
410 |
* @param string $groupType Chart type
|
|
|
411 |
* @param string $id1
|
|
|
412 |
* @param string $id2
|
|
|
413 |
* @param boolean $isMultiLevelSeries
|
|
|
414 |
* @throws PHPExcel_Writer_Exception
|
|
|
415 |
*/
|
|
|
416 |
private function _writeCatAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries)
|
|
|
417 |
{
|
|
|
418 |
$objWriter->startElement('c:catAx');
|
|
|
419 |
|
|
|
420 |
if ($id1 > 0) {
|
|
|
421 |
$objWriter->startElement('c:axId');
|
|
|
422 |
$objWriter->writeAttribute('val', $id1);
|
|
|
423 |
$objWriter->endElement();
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
$objWriter->startElement('c:scaling');
|
|
|
427 |
$objWriter->startElement('c:orientation');
|
|
|
428 |
$objWriter->writeAttribute('val', "minMax");
|
|
|
429 |
$objWriter->endElement();
|
|
|
430 |
$objWriter->endElement();
|
|
|
431 |
|
|
|
432 |
$objWriter->startElement('c:delete');
|
|
|
433 |
$objWriter->writeAttribute('val', 0);
|
|
|
434 |
$objWriter->endElement();
|
|
|
435 |
|
|
|
436 |
$objWriter->startElement('c:axPos');
|
|
|
437 |
$objWriter->writeAttribute('val', "b");
|
|
|
438 |
$objWriter->endElement();
|
|
|
439 |
|
|
|
440 |
if (!is_null($xAxisLabel)) {
|
|
|
441 |
$objWriter->startElement('c:title');
|
|
|
442 |
$objWriter->startElement('c:tx');
|
|
|
443 |
$objWriter->startElement('c:rich');
|
|
|
444 |
|
|
|
445 |
$objWriter->startElement('a:bodyPr');
|
|
|
446 |
$objWriter->endElement();
|
|
|
447 |
|
|
|
448 |
$objWriter->startElement('a:lstStyle');
|
|
|
449 |
$objWriter->endElement();
|
|
|
450 |
|
|
|
451 |
$objWriter->startElement('a:p');
|
|
|
452 |
$objWriter->startElement('a:r');
|
|
|
453 |
|
|
|
454 |
$caption = $xAxisLabel->getCaption();
|
|
|
455 |
if (is_array($caption))
|
|
|
456 |
$caption = $caption[0];
|
|
|
457 |
$objWriter->startElement('a:t');
|
|
|
458 |
// $objWriter->writeAttribute('xml:space', 'preserve');
|
|
|
459 |
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
|
|
|
460 |
$objWriter->endElement();
|
|
|
461 |
|
|
|
462 |
$objWriter->endElement();
|
|
|
463 |
$objWriter->endElement();
|
|
|
464 |
$objWriter->endElement();
|
|
|
465 |
$objWriter->endElement();
|
|
|
466 |
|
|
|
467 |
$layout = $xAxisLabel->getLayout();
|
|
|
468 |
$this->_writeLayout($layout, $objWriter);
|
|
|
469 |
|
|
|
470 |
$objWriter->startElement('c:overlay');
|
|
|
471 |
$objWriter->writeAttribute('val', 0);
|
|
|
472 |
$objWriter->endElement();
|
|
|
473 |
|
|
|
474 |
$objWriter->endElement();
|
|
|
475 |
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
$objWriter->startElement('c:numFmt');
|
|
|
479 |
$objWriter->writeAttribute('formatCode', "General");
|
|
|
480 |
$objWriter->writeAttribute('sourceLinked', 1);
|
|
|
481 |
$objWriter->endElement();
|
|
|
482 |
|
|
|
483 |
$objWriter->startElement('c:majorTickMark');
|
|
|
484 |
$objWriter->writeAttribute('val', "out");
|
|
|
485 |
$objWriter->endElement();
|
|
|
486 |
|
|
|
487 |
$objWriter->startElement('c:minorTickMark');
|
|
|
488 |
$objWriter->writeAttribute('val', "none");
|
|
|
489 |
$objWriter->endElement();
|
|
|
490 |
|
|
|
491 |
$objWriter->startElement('c:tickLblPos');
|
|
|
492 |
$objWriter->writeAttribute('val', "nextTo");
|
|
|
493 |
$objWriter->endElement();
|
|
|
494 |
|
|
|
495 |
if ($id2 > 0) {
|
|
|
496 |
$objWriter->startElement('c:crossAx');
|
|
|
497 |
$objWriter->writeAttribute('val', $id2);
|
|
|
498 |
$objWriter->endElement();
|
|
|
499 |
|
|
|
500 |
$objWriter->startElement('c:crosses');
|
|
|
501 |
$objWriter->writeAttribute('val', "autoZero");
|
|
|
502 |
$objWriter->endElement();
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
$objWriter->startElement('c:auto');
|
|
|
506 |
$objWriter->writeAttribute('val', 1);
|
|
|
507 |
$objWriter->endElement();
|
|
|
508 |
|
|
|
509 |
$objWriter->startElement('c:lblAlgn');
|
|
|
510 |
$objWriter->writeAttribute('val', "ctr");
|
|
|
511 |
$objWriter->endElement();
|
|
|
512 |
|
|
|
513 |
$objWriter->startElement('c:lblOffset');
|
|
|
514 |
$objWriter->writeAttribute('val', 100);
|
|
|
515 |
$objWriter->endElement();
|
|
|
516 |
|
|
|
517 |
if ($isMultiLevelSeries) {
|
|
|
518 |
$objWriter->startElement('c:noMultiLvlLbl');
|
|
|
519 |
$objWriter->writeAttribute('val', 0);
|
|
|
520 |
$objWriter->endElement();
|
|
|
521 |
}
|
|
|
522 |
$objWriter->endElement();
|
|
|
523 |
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
/**
|
|
|
528 |
* Write Value Axis
|
|
|
529 |
*
|
|
|
530 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
531 |
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
532 |
* @param PHPExcel_Chart_Title $yAxisLabel
|
|
|
533 |
* @param string $groupType Chart type
|
|
|
534 |
* @param string $id1
|
|
|
535 |
* @param string $id2
|
|
|
536 |
* @param boolean $isMultiLevelSeries
|
|
|
537 |
* @throws PHPExcel_Writer_Exception
|
|
|
538 |
*/
|
|
|
539 |
private function _writeValAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries)
|
|
|
540 |
{
|
|
|
541 |
$objWriter->startElement('c:valAx');
|
|
|
542 |
|
|
|
543 |
if ($id2 > 0) {
|
|
|
544 |
$objWriter->startElement('c:axId');
|
|
|
545 |
$objWriter->writeAttribute('val', $id2);
|
|
|
546 |
$objWriter->endElement();
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
$objWriter->startElement('c:scaling');
|
|
|
550 |
$objWriter->startElement('c:orientation');
|
|
|
551 |
$objWriter->writeAttribute('val', "minMax");
|
|
|
552 |
$objWriter->endElement();
|
|
|
553 |
$objWriter->endElement();
|
|
|
554 |
|
|
|
555 |
$objWriter->startElement('c:delete');
|
|
|
556 |
$objWriter->writeAttribute('val', 0);
|
|
|
557 |
$objWriter->endElement();
|
|
|
558 |
|
|
|
559 |
$objWriter->startElement('c:axPos');
|
|
|
560 |
$objWriter->writeAttribute('val', "l");
|
|
|
561 |
$objWriter->endElement();
|
|
|
562 |
|
|
|
563 |
$objWriter->startElement('c:majorGridlines');
|
|
|
564 |
$objWriter->endElement();
|
|
|
565 |
|
|
|
566 |
if (!is_null($yAxisLabel)) {
|
|
|
567 |
$objWriter->startElement('c:title');
|
|
|
568 |
$objWriter->startElement('c:tx');
|
|
|
569 |
$objWriter->startElement('c:rich');
|
|
|
570 |
|
|
|
571 |
$objWriter->startElement('a:bodyPr');
|
|
|
572 |
$objWriter->endElement();
|
|
|
573 |
|
|
|
574 |
$objWriter->startElement('a:lstStyle');
|
|
|
575 |
$objWriter->endElement();
|
|
|
576 |
|
|
|
577 |
$objWriter->startElement('a:p');
|
|
|
578 |
$objWriter->startElement('a:r');
|
|
|
579 |
|
|
|
580 |
$caption = $yAxisLabel->getCaption();
|
|
|
581 |
if (is_array($caption))
|
|
|
582 |
$caption = $caption[0];
|
|
|
583 |
$objWriter->startElement('a:t');
|
|
|
584 |
// $objWriter->writeAttribute('xml:space', 'preserve');
|
|
|
585 |
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
|
|
|
586 |
$objWriter->endElement();
|
|
|
587 |
|
|
|
588 |
$objWriter->endElement();
|
|
|
589 |
$objWriter->endElement();
|
|
|
590 |
$objWriter->endElement();
|
|
|
591 |
$objWriter->endElement();
|
|
|
592 |
|
|
|
593 |
if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
594 |
$layout = $yAxisLabel->getLayout();
|
|
|
595 |
$this->_writeLayout($layout, $objWriter);
|
|
|
596 |
}
|
|
|
597 |
|
|
|
598 |
$objWriter->startElement('c:overlay');
|
|
|
599 |
$objWriter->writeAttribute('val', 0);
|
|
|
600 |
$objWriter->endElement();
|
|
|
601 |
|
|
|
602 |
$objWriter->endElement();
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
$objWriter->startElement('c:numFmt');
|
|
|
606 |
$objWriter->writeAttribute('formatCode', "General");
|
|
|
607 |
$objWriter->writeAttribute('sourceLinked', 1);
|
|
|
608 |
$objWriter->endElement();
|
|
|
609 |
|
|
|
610 |
$objWriter->startElement('c:majorTickMark');
|
|
|
611 |
$objWriter->writeAttribute('val', "out");
|
|
|
612 |
$objWriter->endElement();
|
|
|
613 |
|
|
|
614 |
$objWriter->startElement('c:minorTickMark');
|
|
|
615 |
$objWriter->writeAttribute('val', "none");
|
|
|
616 |
$objWriter->endElement();
|
|
|
617 |
|
|
|
618 |
$objWriter->startElement('c:tickLblPos');
|
|
|
619 |
$objWriter->writeAttribute('val', "nextTo");
|
|
|
620 |
$objWriter->endElement();
|
|
|
621 |
|
|
|
622 |
if ($id1 > 0) {
|
|
|
623 |
$objWriter->startElement('c:crossAx');
|
|
|
624 |
$objWriter->writeAttribute('val', $id2);
|
|
|
625 |
$objWriter->endElement();
|
|
|
626 |
|
|
|
627 |
$objWriter->startElement('c:crosses');
|
|
|
628 |
$objWriter->writeAttribute('val', "autoZero");
|
|
|
629 |
$objWriter->endElement();
|
|
|
630 |
|
|
|
631 |
$objWriter->startElement('c:crossBetween');
|
|
|
632 |
$objWriter->writeAttribute('val', "midCat");
|
|
|
633 |
$objWriter->endElement();
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
if ($isMultiLevelSeries) {
|
|
|
637 |
if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
638 |
$objWriter->startElement('c:noMultiLvlLbl');
|
|
|
639 |
$objWriter->writeAttribute('val', 0);
|
|
|
640 |
$objWriter->endElement();
|
|
|
641 |
}
|
|
|
642 |
}
|
|
|
643 |
$objWriter->endElement();
|
|
|
644 |
|
|
|
645 |
}
|
|
|
646 |
|
|
|
647 |
|
|
|
648 |
/**
|
|
|
649 |
* Get the data series type(s) for a chart plot series
|
|
|
650 |
*
|
|
|
651 |
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
652 |
* @return string|array
|
|
|
653 |
* @throws PHPExcel_Writer_Exception
|
|
|
654 |
*/
|
|
|
655 |
private static function _getChartType($plotArea)
|
|
|
656 |
{
|
|
|
657 |
$groupCount = $plotArea->getPlotGroupCount();
|
|
|
658 |
|
|
|
659 |
if ($groupCount == 1) {
|
|
|
660 |
$chartType = array($plotArea->getPlotGroupByIndex(0)->getPlotType());
|
|
|
661 |
} else {
|
|
|
662 |
$chartTypes = array();
|
|
|
663 |
for($i = 0; $i < $groupCount; ++$i) {
|
|
|
664 |
$chartTypes[] = $plotArea->getPlotGroupByIndex($i)->getPlotType();
|
|
|
665 |
}
|
|
|
666 |
$chartType = array_unique($chartTypes);
|
|
|
667 |
if (count($chartTypes) == 0) {
|
|
|
668 |
throw new PHPExcel_Writer_Exception('Chart is not yet implemented');
|
|
|
669 |
}
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
return $chartType;
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
/**
|
|
|
676 |
* Write Plot Group (series of related plots)
|
|
|
677 |
*
|
|
|
678 |
* @param PHPExcel_Chart_DataSeries $plotGroup
|
|
|
679 |
* @param string $groupType Type of plot for dataseries
|
|
|
680 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
681 |
* @param boolean &$catIsMultiLevelSeries Is category a multi-series category
|
|
|
682 |
* @param boolean &$valIsMultiLevelSeries Is value set a multi-series set
|
|
|
683 |
* @param string &$plotGroupingType Type of grouping for multi-series values
|
|
|
684 |
* @param PHPExcel_Worksheet $pSheet
|
|
|
685 |
* @throws PHPExcel_Writer_Exception
|
|
|
686 |
*/
|
|
|
687 |
private function _writePlotGroup( $plotGroup,
|
|
|
688 |
$groupType,
|
|
|
689 |
$objWriter,
|
|
|
690 |
&$catIsMultiLevelSeries,
|
|
|
691 |
&$valIsMultiLevelSeries,
|
|
|
692 |
&$plotGroupingType,
|
|
|
693 |
PHPExcel_Worksheet $pSheet
|
|
|
694 |
)
|
|
|
695 |
{
|
|
|
696 |
if (is_null($plotGroup)) {
|
|
|
697 |
return;
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
|
|
701 |
($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
|
|
|
702 |
$objWriter->startElement('c:barDir');
|
|
|
703 |
$objWriter->writeAttribute('val', $plotGroup->getPlotDirection());
|
|
|
704 |
$objWriter->endElement();
|
|
|
705 |
}
|
|
|
706 |
|
|
|
707 |
if (!is_null($plotGroup->getPlotGrouping())) {
|
|
|
708 |
$plotGroupingType = $plotGroup->getPlotGrouping();
|
|
|
709 |
$objWriter->startElement('c:grouping');
|
|
|
710 |
$objWriter->writeAttribute('val', $plotGroupingType);
|
|
|
711 |
$objWriter->endElement();
|
|
|
712 |
}
|
|
|
713 |
|
|
|
714 |
// Get these details before the loop, because we can use the count to check for varyColors
|
|
|
715 |
$plotSeriesOrder = $plotGroup->getPlotOrder();
|
|
|
716 |
$plotSeriesCount = count($plotSeriesOrder);
|
|
|
717 |
|
|
|
718 |
if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_RADARCHART) &&
|
|
|
719 |
($groupType !== PHPExcel_Chart_DataSeries::TYPE_STOCKCHART)) {
|
|
|
720 |
|
|
|
721 |
if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
|
|
|
722 |
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
|
|
|
723 |
($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
|
|
|
724 |
($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) ||
|
|
|
725 |
($plotSeriesCount > 1)) {
|
|
|
726 |
$objWriter->startElement('c:varyColors');
|
|
|
727 |
$objWriter->writeAttribute('val', 1);
|
|
|
728 |
$objWriter->endElement();
|
|
|
729 |
} else {
|
|
|
730 |
$objWriter->startElement('c:varyColors');
|
|
|
731 |
$objWriter->writeAttribute('val', 0);
|
|
|
732 |
$objWriter->endElement();
|
|
|
733 |
}
|
|
|
734 |
}
|
|
|
735 |
}
|
|
|
736 |
|
|
|
737 |
foreach($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
|
|
|
738 |
$objWriter->startElement('c:ser');
|
|
|
739 |
|
|
|
740 |
$objWriter->startElement('c:idx');
|
|
|
741 |
$objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx);
|
|
|
742 |
$objWriter->endElement();
|
|
|
743 |
|
|
|
744 |
$objWriter->startElement('c:order');
|
|
|
745 |
$objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesRef);
|
|
|
746 |
$objWriter->endElement();
|
|
|
747 |
|
|
|
748 |
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
|
|
|
749 |
($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
|
|
|
750 |
($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
|
751 |
|
|
|
752 |
$objWriter->startElement('c:dPt');
|
|
|
753 |
$objWriter->startElement('c:idx');
|
|
|
754 |
$objWriter->writeAttribute('val', 3);
|
|
|
755 |
$objWriter->endElement();
|
|
|
756 |
|
|
|
757 |
$objWriter->startElement('c:bubble3D');
|
|
|
758 |
$objWriter->writeAttribute('val', 0);
|
|
|
759 |
$objWriter->endElement();
|
|
|
760 |
|
|
|
761 |
$objWriter->startElement('c:spPr');
|
|
|
762 |
$objWriter->startElement('a:solidFill');
|
|
|
763 |
$objWriter->startElement('a:srgbClr');
|
|
|
764 |
$objWriter->writeAttribute('val', 'FF9900');
|
|
|
765 |
$objWriter->endElement();
|
|
|
766 |
$objWriter->endElement();
|
|
|
767 |
$objWriter->endElement();
|
|
|
768 |
$objWriter->endElement();
|
|
|
769 |
}
|
|
|
770 |
|
|
|
771 |
// Labels
|
|
|
772 |
$plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef);
|
|
|
773 |
if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) {
|
|
|
774 |
$objWriter->startElement('c:tx');
|
|
|
775 |
$objWriter->startElement('c:strRef');
|
|
|
776 |
$this->_writePlotSeriesLabel($plotSeriesLabel, $objWriter);
|
|
|
777 |
$objWriter->endElement();
|
|
|
778 |
$objWriter->endElement();
|
|
|
779 |
}
|
|
|
780 |
|
|
|
781 |
// Formatting for the points
|
|
|
782 |
if ($groupType == PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
|
|
|
783 |
$objWriter->startElement('c:spPr');
|
|
|
784 |
$objWriter->startElement('a:ln');
|
|
|
785 |
$objWriter->writeAttribute('w', 12700);
|
|
|
786 |
$objWriter->endElement();
|
|
|
787 |
$objWriter->endElement();
|
|
|
788 |
}
|
|
|
789 |
|
|
|
790 |
$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
|
|
|
791 |
if ($plotSeriesValues) {
|
|
|
792 |
$plotSeriesMarker = $plotSeriesValues->getPointMarker();
|
|
|
793 |
if ($plotSeriesMarker) {
|
|
|
794 |
$objWriter->startElement('c:marker');
|
|
|
795 |
$objWriter->startElement('c:symbol');
|
|
|
796 |
$objWriter->writeAttribute('val', $plotSeriesMarker);
|
|
|
797 |
$objWriter->endElement();
|
|
|
798 |
|
|
|
799 |
if ($plotSeriesMarker !== 'none') {
|
|
|
800 |
$objWriter->startElement('c:size');
|
|
|
801 |
$objWriter->writeAttribute('val', 3);
|
|
|
802 |
$objWriter->endElement();
|
|
|
803 |
}
|
|
|
804 |
$objWriter->endElement();
|
|
|
805 |
}
|
|
|
806 |
}
|
|
|
807 |
|
|
|
808 |
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
|
|
809 |
($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D) ||
|
|
|
810 |
($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART)) {
|
|
|
811 |
|
|
|
812 |
$objWriter->startElement('c:invertIfNegative');
|
|
|
813 |
$objWriter->writeAttribute('val', 0);
|
|
|
814 |
$objWriter->endElement();
|
|
|
815 |
}
|
|
|
816 |
|
|
|
817 |
// Category Labels
|
|
|
818 |
$plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef);
|
|
|
819 |
if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) {
|
|
|
820 |
$catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries();
|
|
|
821 |
|
|
|
822 |
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
|
|
|
823 |
($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
|
|
|
824 |
($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
|
825 |
|
|
|
826 |
if (!is_null($plotGroup->getPlotStyle())) {
|
|
|
827 |
$plotStyle = $plotGroup->getPlotStyle();
|
|
|
828 |
if ($plotStyle) {
|
|
|
829 |
$objWriter->startElement('c:explosion');
|
|
|
830 |
$objWriter->writeAttribute('val', 25);
|
|
|
831 |
$objWriter->endElement();
|
|
|
832 |
}
|
|
|
833 |
}
|
|
|
834 |
}
|
|
|
835 |
|
|
|
836 |
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) ||
|
|
|
837 |
($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) {
|
|
|
838 |
$objWriter->startElement('c:xVal');
|
|
|
839 |
} else {
|
|
|
840 |
$objWriter->startElement('c:cat');
|
|
|
841 |
}
|
|
|
842 |
|
|
|
843 |
$this->_writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str', $pSheet);
|
|
|
844 |
$objWriter->endElement();
|
|
|
845 |
}
|
|
|
846 |
|
|
|
847 |
// Values
|
|
|
848 |
if ($plotSeriesValues) {
|
|
|
849 |
$valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries();
|
|
|
850 |
|
|
|
851 |
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) ||
|
|
|
852 |
($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) {
|
|
|
853 |
$objWriter->startElement('c:yVal');
|
|
|
854 |
} else {
|
|
|
855 |
$objWriter->startElement('c:val');
|
|
|
856 |
}
|
|
|
857 |
|
|
|
858 |
$this->_writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num', $pSheet);
|
|
|
859 |
$objWriter->endElement();
|
|
|
860 |
}
|
|
|
861 |
|
|
|
862 |
if ($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
863 |
$this->_writeBubbles($plotSeriesValues, $objWriter, $pSheet);
|
|
|
864 |
}
|
|
|
865 |
|
|
|
866 |
$objWriter->endElement();
|
|
|
867 |
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
$this->_seriesIndex += $plotSeriesIdx + 1;
|
|
|
871 |
}
|
|
|
872 |
|
|
|
873 |
/**
|
|
|
874 |
* Write Plot Series Label
|
|
|
875 |
*
|
|
|
876 |
* @param PHPExcel_Chart_DataSeriesValues $plotSeriesLabel
|
|
|
877 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
878 |
* @throws PHPExcel_Writer_Exception
|
|
|
879 |
*/
|
|
|
880 |
private function _writePlotSeriesLabel($plotSeriesLabel, $objWriter)
|
|
|
881 |
{
|
|
|
882 |
if (is_null($plotSeriesLabel)) {
|
|
|
883 |
return;
|
|
|
884 |
}
|
|
|
885 |
|
|
|
886 |
$objWriter->startElement('c:f');
|
|
|
887 |
$objWriter->writeRawData($plotSeriesLabel->getDataSource());
|
|
|
888 |
$objWriter->endElement();
|
|
|
889 |
|
|
|
890 |
$objWriter->startElement('c:strCache');
|
|
|
891 |
$objWriter->startElement('c:ptCount');
|
|
|
892 |
$objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount() );
|
|
|
893 |
$objWriter->endElement();
|
|
|
894 |
|
|
|
895 |
foreach($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) {
|
|
|
896 |
$objWriter->startElement('c:pt');
|
|
|
897 |
$objWriter->writeAttribute('idx', $plotLabelKey );
|
|
|
898 |
|
|
|
899 |
$objWriter->startElement('c:v');
|
|
|
900 |
$objWriter->writeRawData( $plotLabelValue );
|
|
|
901 |
$objWriter->endElement();
|
|
|
902 |
$objWriter->endElement();
|
|
|
903 |
}
|
|
|
904 |
$objWriter->endElement();
|
|
|
905 |
|
|
|
906 |
}
|
|
|
907 |
|
|
|
908 |
/**
|
|
|
909 |
* Write Plot Series Values
|
|
|
910 |
*
|
|
|
911 |
* @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues
|
|
|
912 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
913 |
* @param string $groupType Type of plot for dataseries
|
|
|
914 |
* @param string $dataType Datatype of series values
|
|
|
915 |
* @param PHPExcel_Worksheet $pSheet
|
|
|
916 |
* @throws PHPExcel_Writer_Exception
|
|
|
917 |
*/
|
|
|
918 |
private function _writePlotSeriesValues( $plotSeriesValues,
|
|
|
919 |
$objWriter,
|
|
|
920 |
$groupType,
|
|
|
921 |
$dataType='str',
|
|
|
922 |
PHPExcel_Worksheet $pSheet
|
|
|
923 |
)
|
|
|
924 |
{
|
|
|
925 |
if (is_null($plotSeriesValues)) {
|
|
|
926 |
return;
|
|
|
927 |
}
|
|
|
928 |
|
|
|
929 |
if ($plotSeriesValues->isMultiLevelSeries()) {
|
|
|
930 |
$levelCount = $plotSeriesValues->multiLevelCount();
|
|
|
931 |
|
|
|
932 |
$objWriter->startElement('c:multiLvlStrRef');
|
|
|
933 |
|
|
|
934 |
$objWriter->startElement('c:f');
|
|
|
935 |
$objWriter->writeRawData( $plotSeriesValues->getDataSource() );
|
|
|
936 |
$objWriter->endElement();
|
|
|
937 |
|
|
|
938 |
$objWriter->startElement('c:multiLvlStrCache');
|
|
|
939 |
|
|
|
940 |
$objWriter->startElement('c:ptCount');
|
|
|
941 |
$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
|
|
|
942 |
$objWriter->endElement();
|
|
|
943 |
|
|
|
944 |
for ($level = 0; $level < $levelCount; ++$level) {
|
|
|
945 |
$objWriter->startElement('c:lvl');
|
|
|
946 |
|
|
|
947 |
foreach($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
|
|
|
948 |
if (isset($plotSeriesValue[$level])) {
|
|
|
949 |
$objWriter->startElement('c:pt');
|
|
|
950 |
$objWriter->writeAttribute('idx', $plotSeriesKey );
|
|
|
951 |
|
|
|
952 |
$objWriter->startElement('c:v');
|
|
|
953 |
$objWriter->writeRawData( $plotSeriesValue[$level] );
|
|
|
954 |
$objWriter->endElement();
|
|
|
955 |
$objWriter->endElement();
|
|
|
956 |
}
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
$objWriter->endElement();
|
|
|
960 |
}
|
|
|
961 |
|
|
|
962 |
$objWriter->endElement();
|
|
|
963 |
|
|
|
964 |
$objWriter->endElement();
|
|
|
965 |
} else {
|
|
|
966 |
$objWriter->startElement('c:'.$dataType.'Ref');
|
|
|
967 |
|
|
|
968 |
$objWriter->startElement('c:f');
|
|
|
969 |
$objWriter->writeRawData( $plotSeriesValues->getDataSource() );
|
|
|
970 |
$objWriter->endElement();
|
|
|
971 |
|
|
|
972 |
$objWriter->startElement('c:'.$dataType.'Cache');
|
|
|
973 |
|
|
|
974 |
if (($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
|
|
975 |
($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
|
|
976 |
($groupType != PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
|
977 |
|
|
|
978 |
if (($plotSeriesValues->getFormatCode() !== NULL) &&
|
|
|
979 |
($plotSeriesValues->getFormatCode() !== '')) {
|
|
|
980 |
$objWriter->startElement('c:formatCode');
|
|
|
981 |
$objWriter->writeRawData( $plotSeriesValues->getFormatCode() );
|
|
|
982 |
$objWriter->endElement();
|
|
|
983 |
}
|
|
|
984 |
}
|
|
|
985 |
|
|
|
986 |
$objWriter->startElement('c:ptCount');
|
|
|
987 |
$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
|
|
|
988 |
$objWriter->endElement();
|
|
|
989 |
|
|
|
990 |
$dataValues = $plotSeriesValues->getDataValues();
|
|
|
991 |
if (!empty($dataValues)) {
|
|
|
992 |
if (is_array($dataValues)) {
|
|
|
993 |
foreach($dataValues as $plotSeriesKey => $plotSeriesValue) {
|
|
|
994 |
$objWriter->startElement('c:pt');
|
|
|
995 |
$objWriter->writeAttribute('idx', $plotSeriesKey );
|
|
|
996 |
|
|
|
997 |
$objWriter->startElement('c:v');
|
|
|
998 |
$objWriter->writeRawData( $plotSeriesValue );
|
|
|
999 |
$objWriter->endElement();
|
|
|
1000 |
$objWriter->endElement();
|
|
|
1001 |
}
|
|
|
1002 |
}
|
|
|
1003 |
}
|
|
|
1004 |
|
|
|
1005 |
$objWriter->endElement();
|
|
|
1006 |
|
|
|
1007 |
$objWriter->endElement();
|
|
|
1008 |
}
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
/**
|
|
|
1012 |
* Write Bubble Chart Details
|
|
|
1013 |
*
|
|
|
1014 |
* @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues
|
|
|
1015 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
1016 |
* @throws PHPExcel_Writer_Exception
|
|
|
1017 |
*/
|
|
|
1018 |
private function _writeBubbles($plotSeriesValues, $objWriter, PHPExcel_Worksheet $pSheet)
|
|
|
1019 |
{
|
|
|
1020 |
if (is_null($plotSeriesValues)) {
|
|
|
1021 |
return;
|
|
|
1022 |
}
|
|
|
1023 |
|
|
|
1024 |
$objWriter->startElement('c:bubbleSize');
|
|
|
1025 |
$objWriter->startElement('c:numLit');
|
|
|
1026 |
|
|
|
1027 |
$objWriter->startElement('c:formatCode');
|
|
|
1028 |
$objWriter->writeRawData( 'General' );
|
|
|
1029 |
$objWriter->endElement();
|
|
|
1030 |
|
|
|
1031 |
$objWriter->startElement('c:ptCount');
|
|
|
1032 |
$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
|
|
|
1033 |
$objWriter->endElement();
|
|
|
1034 |
|
|
|
1035 |
$dataValues = $plotSeriesValues->getDataValues();
|
|
|
1036 |
if (!empty($dataValues)) {
|
|
|
1037 |
if (is_array($dataValues)) {
|
|
|
1038 |
foreach($dataValues as $plotSeriesKey => $plotSeriesValue) {
|
|
|
1039 |
$objWriter->startElement('c:pt');
|
|
|
1040 |
$objWriter->writeAttribute('idx', $plotSeriesKey );
|
|
|
1041 |
$objWriter->startElement('c:v');
|
|
|
1042 |
$objWriter->writeRawData( 1 );
|
|
|
1043 |
$objWriter->endElement();
|
|
|
1044 |
$objWriter->endElement();
|
|
|
1045 |
}
|
|
|
1046 |
}
|
|
|
1047 |
}
|
|
|
1048 |
|
|
|
1049 |
$objWriter->endElement();
|
|
|
1050 |
$objWriter->endElement();
|
|
|
1051 |
|
|
|
1052 |
$objWriter->startElement('c:bubble3D');
|
|
|
1053 |
$objWriter->writeAttribute('val', 0 );
|
|
|
1054 |
$objWriter->endElement();
|
|
|
1055 |
}
|
|
|
1056 |
|
|
|
1057 |
/**
|
|
|
1058 |
* Write Layout
|
|
|
1059 |
*
|
|
|
1060 |
* @param PHPExcel_Chart_Layout $layout
|
|
|
1061 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
1062 |
* @throws PHPExcel_Writer_Exception
|
|
|
1063 |
*/
|
|
|
1064 |
private function _writeLayout(PHPExcel_Chart_Layout $layout = NULL, $objWriter)
|
|
|
1065 |
{
|
|
|
1066 |
$objWriter->startElement('c:layout');
|
|
|
1067 |
|
|
|
1068 |
if (!is_null($layout)) {
|
|
|
1069 |
$objWriter->startElement('c:manualLayout');
|
|
|
1070 |
|
|
|
1071 |
$layoutTarget = $layout->getLayoutTarget();
|
|
|
1072 |
if (!is_null($layoutTarget)) {
|
|
|
1073 |
$objWriter->startElement('c:layoutTarget');
|
|
|
1074 |
$objWriter->writeAttribute('val', $layoutTarget);
|
|
|
1075 |
$objWriter->endElement();
|
|
|
1076 |
}
|
|
|
1077 |
|
|
|
1078 |
$xMode = $layout->getXMode();
|
|
|
1079 |
if (!is_null($xMode)) {
|
|
|
1080 |
$objWriter->startElement('c:xMode');
|
|
|
1081 |
$objWriter->writeAttribute('val', $xMode);
|
|
|
1082 |
$objWriter->endElement();
|
|
|
1083 |
}
|
|
|
1084 |
|
|
|
1085 |
$yMode = $layout->getYMode();
|
|
|
1086 |
if (!is_null($yMode)) {
|
|
|
1087 |
$objWriter->startElement('c:yMode');
|
|
|
1088 |
$objWriter->writeAttribute('val', $yMode);
|
|
|
1089 |
$objWriter->endElement();
|
|
|
1090 |
}
|
|
|
1091 |
|
|
|
1092 |
$x = $layout->getXPosition();
|
|
|
1093 |
if (!is_null($x)) {
|
|
|
1094 |
$objWriter->startElement('c:x');
|
|
|
1095 |
$objWriter->writeAttribute('val', $x);
|
|
|
1096 |
$objWriter->endElement();
|
|
|
1097 |
}
|
|
|
1098 |
|
|
|
1099 |
$y = $layout->getYPosition();
|
|
|
1100 |
if (!is_null($y)) {
|
|
|
1101 |
$objWriter->startElement('c:y');
|
|
|
1102 |
$objWriter->writeAttribute('val', $y);
|
|
|
1103 |
$objWriter->endElement();
|
|
|
1104 |
}
|
|
|
1105 |
|
|
|
1106 |
$w = $layout->getWidth();
|
|
|
1107 |
if (!is_null($w)) {
|
|
|
1108 |
$objWriter->startElement('c:w');
|
|
|
1109 |
$objWriter->writeAttribute('val', $w);
|
|
|
1110 |
$objWriter->endElement();
|
|
|
1111 |
}
|
|
|
1112 |
|
|
|
1113 |
$h = $layout->getHeight();
|
|
|
1114 |
if (!is_null($h)) {
|
|
|
1115 |
$objWriter->startElement('c:h');
|
|
|
1116 |
$objWriter->writeAttribute('val', $h);
|
|
|
1117 |
$objWriter->endElement();
|
|
|
1118 |
}
|
|
|
1119 |
|
|
|
1120 |
$objWriter->endElement();
|
|
|
1121 |
}
|
|
|
1122 |
|
|
|
1123 |
$objWriter->endElement();
|
|
|
1124 |
}
|
|
|
1125 |
|
|
|
1126 |
/**
|
|
|
1127 |
* Write Alternate Content block
|
|
|
1128 |
*
|
|
|
1129 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
1130 |
* @throws PHPExcel_Writer_Exception
|
|
|
1131 |
*/
|
|
|
1132 |
private function _writeAlternateContent($objWriter)
|
|
|
1133 |
{
|
|
|
1134 |
$objWriter->startElement('mc:AlternateContent');
|
|
|
1135 |
$objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
|
|
|
1136 |
|
|
|
1137 |
$objWriter->startElement('mc:Choice');
|
|
|
1138 |
$objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart');
|
|
|
1139 |
$objWriter->writeAttribute('Requires', 'c14');
|
|
|
1140 |
|
|
|
1141 |
$objWriter->startElement('c14:style');
|
|
|
1142 |
$objWriter->writeAttribute('val', '102');
|
|
|
1143 |
$objWriter->endElement();
|
|
|
1144 |
$objWriter->endElement();
|
|
|
1145 |
|
|
|
1146 |
$objWriter->startElement('mc:Fallback');
|
|
|
1147 |
$objWriter->startElement('c:style');
|
|
|
1148 |
$objWriter->writeAttribute('val', '2');
|
|
|
1149 |
$objWriter->endElement();
|
|
|
1150 |
$objWriter->endElement();
|
|
|
1151 |
|
|
|
1152 |
$objWriter->endElement();
|
|
|
1153 |
}
|
|
|
1154 |
|
|
|
1155 |
/**
|
|
|
1156 |
* Write Printer Settings
|
|
|
1157 |
*
|
|
|
1158 |
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
1159 |
* @throws PHPExcel_Writer_Exception
|
|
|
1160 |
*/
|
|
|
1161 |
private function _writePrintSettings($objWriter)
|
|
|
1162 |
{
|
|
|
1163 |
$objWriter->startElement('c:printSettings');
|
|
|
1164 |
|
|
|
1165 |
$objWriter->startElement('c:headerFooter');
|
|
|
1166 |
$objWriter->endElement();
|
|
|
1167 |
|
|
|
1168 |
$objWriter->startElement('c:pageMargins');
|
|
|
1169 |
$objWriter->writeAttribute('footer', 0.3);
|
|
|
1170 |
$objWriter->writeAttribute('header', 0.3);
|
|
|
1171 |
$objWriter->writeAttribute('r', 0.7);
|
|
|
1172 |
$objWriter->writeAttribute('l', 0.7);
|
|
|
1173 |
$objWriter->writeAttribute('t', 0.75);
|
|
|
1174 |
$objWriter->writeAttribute('b', 0.75);
|
|
|
1175 |
$objWriter->endElement();
|
|
|
1176 |
|
|
|
1177 |
$objWriter->startElement('c:pageSetup');
|
|
|
1178 |
$objWriter->writeAttribute('orientation', "portrait");
|
|
|
1179 |
$objWriter->endElement();
|
|
|
1180 |
|
|
|
1181 |
$objWriter->endElement();
|
|
|
1182 |
}
|
|
|
1183 |
|
|
|
1184 |
}
|