2012-02-20 20:49:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPExcel
|
|
|
|
*
|
2012-03-03 21:08:29 +00:00
|
|
|
* Copyright (c) 2006 - 2012 PHPExcel
|
2012-02-20 20:49:25 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* @category PHPExcel
|
|
|
|
* @package PHPExcel_Writer_Excel2007
|
2012-03-03 21:08:29 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2012-02-20 20:49:25 +00:00
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
|
* @version ##VERSION##, ##DATE##
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHPExcel_Writer_Excel2007_Chart
|
|
|
|
*
|
|
|
|
* @category PHPExcel
|
|
|
|
* @package PHPExcel_Writer_Excel2007
|
2012-03-03 21:08:29 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2012-02-20 20:49:25 +00:00
|
|
|
*/
|
|
|
|
class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPart
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Write charts to XML format
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart $pChart
|
|
|
|
* @return string XML Output
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-02-20 20:49:25 +00:00
|
|
|
*/
|
|
|
|
public function writeChart(PHPExcel_Chart $pChart = null)
|
|
|
|
{
|
|
|
|
// Create XML writer
|
|
|
|
$objWriter = null;
|
|
|
|
if ($this->getParentWriter()->getUseDiskCaching()) {
|
|
|
|
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
|
|
|
} else {
|
|
|
|
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
|
|
|
|
}
|
2012-04-07 20:54:55 +00:00
|
|
|
// Ensure that data series values are up-to-date before we save
|
|
|
|
$pChart->refresh();
|
2012-02-20 20:49:25 +00:00
|
|
|
|
|
|
|
// XML header
|
|
|
|
$objWriter->startDocument('1.0','UTF-8','yes');
|
|
|
|
|
|
|
|
// c:chartSpace
|
|
|
|
$objWriter->startElement('c:chartSpace');
|
|
|
|
$objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
|
|
|
|
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
|
|
|
|
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:date1904');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->startElement('c:lang');
|
|
|
|
$objWriter->writeAttribute('val', "en-GB");
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->startElement('c:roundedCorners');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$this->_writeAlternateContent($objWriter);
|
|
|
|
|
|
|
|
$objWriter->startElement('c:chart');
|
|
|
|
|
|
|
|
$this->_writeTitle($pChart->getTitle(), $objWriter);
|
|
|
|
|
|
|
|
$objWriter->startElement('c:autoTitleDeleted');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-07-20 22:13:16 +00:00
|
|
|
$this->_writePlotArea($pChart->getPlotArea(),
|
|
|
|
$pChart->getXAxisLabel(),
|
|
|
|
$pChart->getYAxisLabel(),
|
|
|
|
$objWriter,
|
|
|
|
$pChart->getWorksheet()
|
|
|
|
);
|
2012-02-20 20:49:25 +00:00
|
|
|
|
|
|
|
$this->_writeLegend($pChart->getLegend(), $objWriter);
|
|
|
|
|
|
|
|
|
|
|
|
$objWriter->startElement('c:plotVisOnly');
|
|
|
|
$objWriter->writeAttribute('val', 1);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:dispBlanksAs');
|
|
|
|
$objWriter->writeAttribute('val', "gap");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showDLblsOverMax');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$this->_writePrintSettings($objWriter);
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
// Return
|
|
|
|
return $objWriter->getData();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Chart Title
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_Title $title
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private function _writeTitle(PHPExcel_Chart_Title $title = null, $objWriter)
|
|
|
|
{
|
|
|
|
if (is_null($title)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->startElement('c:title');
|
|
|
|
$objWriter->startElement('c:tx');
|
|
|
|
$objWriter->startElement('c:rich');
|
2012-02-23 17:20:25 +00:00
|
|
|
|
|
|
|
$objWriter->startElement('a:bodyPr');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('a:lstStyle');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('a:p');
|
|
|
|
|
|
|
|
$caption = $title->getCaption();
|
2012-05-13 18:15:09 +00:00
|
|
|
if ((is_array($caption)) && (count($caption) > 0))
|
2012-02-20 20:49:25 +00:00
|
|
|
$caption = $caption[0];
|
2012-02-23 17:20:25 +00:00
|
|
|
$this->getParentWriter()->getWriterPart('stringtable')->writeRichTextForCharts($objWriter, $caption, 'a');
|
2012-02-20 20:49:25 +00:00
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$layout = $title->getLayout();
|
|
|
|
$this->_writeLayout($layout, $objWriter);
|
|
|
|
|
|
|
|
$objWriter->startElement('c:overlay');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Chart Legend
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_Legend $legend
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private function _writeLegend(PHPExcel_Chart_Legend $legend = null, $objWriter)
|
|
|
|
{
|
|
|
|
if (is_null($legend)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->startElement('c:legend');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:legendPos');
|
|
|
|
$objWriter->writeAttribute('val', $legend->getPosition());
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$layout = $legend->getLayout();
|
|
|
|
$this->_writeLayout($layout, $objWriter);
|
|
|
|
|
|
|
|
$objWriter->startElement('c:overlay');
|
|
|
|
$objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:txPr');
|
|
|
|
$objWriter->startElement('a:bodyPr');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('a:lstStyle');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('a:p');
|
|
|
|
$objWriter->startElement('a:pPr');
|
|
|
|
$objWriter->writeAttribute('rtl', 0);
|
|
|
|
|
|
|
|
$objWriter->startElement('a:defRPr');
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('a:endParaRPr');
|
|
|
|
$objWriter->writeAttribute('lang', "en-US");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Chart Plot Area
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
|
* @param PHPExcel_Chart_Title $xAxisLabel
|
|
|
|
* @param PHPExcel_Chart_Title $yAxisLabel
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private function _writePlotArea(PHPExcel_Chart_PlotArea $plotArea,
|
|
|
|
PHPExcel_Chart_Title $xAxisLabel = NULL,
|
|
|
|
PHPExcel_Chart_Title $yAxisLabel = NULL,
|
2012-07-20 22:13:16 +00:00
|
|
|
$objWriter,
|
|
|
|
PHPExcel_Worksheet $pSheet)
|
2012-02-20 20:49:25 +00:00
|
|
|
{
|
|
|
|
if (is_null($plotArea)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$id1 = $id2 = 0;
|
2013-02-19 12:23:38 +00:00
|
|
|
$this->_seriesIndex = 0;
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:plotArea');
|
|
|
|
|
|
|
|
$layout = $plotArea->getLayout();
|
2012-09-17 22:23:55 +00:00
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$this->_writeLayout($layout, $objWriter);
|
|
|
|
|
|
|
|
$chartTypes = self::_getChartType($plotArea);
|
|
|
|
$catIsMultiLevelSeries = $valIsMultiLevelSeries = FALSE;
|
2012-02-24 13:30:22 +00:00
|
|
|
$plotGroupingType = '';
|
2012-02-20 20:49:25 +00:00
|
|
|
foreach($chartTypes as $chartType) {
|
|
|
|
$objWriter->startElement('c:'.$chartType);
|
|
|
|
|
|
|
|
$groupCount = $plotArea->getPlotGroupCount();
|
|
|
|
for($i = 0; $i < $groupCount; ++$i) {
|
|
|
|
$plotGroup = $plotArea->getPlotGroupByIndex($i);
|
|
|
|
$groupType = $plotGroup->getPlotType();
|
|
|
|
if ($groupType == $chartType) {
|
2012-02-24 23:58:02 +00:00
|
|
|
|
2012-02-26 16:27:05 +00:00
|
|
|
$plotStyle = $plotGroup->getPlotStyle();
|
2012-02-24 23:58:02 +00:00
|
|
|
if ($groupType === PHPExcel_Chart_DataSeries::TYPE_RADARCHART) {
|
|
|
|
$objWriter->startElement('c:radarStyle');
|
2012-02-26 16:27:05 +00:00
|
|
|
$objWriter->writeAttribute('val', $plotStyle );
|
2012-02-24 23:58:02 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
} elseif ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART) {
|
|
|
|
$objWriter->startElement('c:scatterStyle');
|
2012-02-26 16:27:05 +00:00
|
|
|
$objWriter->writeAttribute('val', $plotStyle );
|
2012-02-24 23:58:02 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-07-20 22:13:16 +00:00
|
|
|
$this->_writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet);
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-17 22:23:55 +00:00
|
|
|
$this->_writeDataLbls($objWriter, $layout);
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-03-04 11:30:33 +00:00
|
|
|
if ($chartType === PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
|
2012-02-24 13:13:38 +00:00
|
|
|
// Line only, Line3D can't be smoothed
|
2012-02-23 17:20:25 +00:00
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:smooth');
|
|
|
|
$objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() );
|
|
|
|
$objWriter->endElement();
|
2012-03-04 11:30:33 +00:00
|
|
|
} elseif (($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
|
|
|
($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
|
2012-02-23 17:20:25 +00:00
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:gapWidth');
|
|
|
|
$objWriter->writeAttribute('val', 150 );
|
|
|
|
$objWriter->endElement();
|
2012-02-24 13:30:22 +00:00
|
|
|
|
|
|
|
if ($plotGroupingType == 'percentStacked' ||
|
|
|
|
$plotGroupingType == 'stacked') {
|
|
|
|
|
|
|
|
$objWriter->startElement('c:overlap');
|
|
|
|
$objWriter->writeAttribute('val', 100 );
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
2012-03-04 11:30:33 +00:00
|
|
|
} elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
2012-02-24 13:30:22 +00:00
|
|
|
|
2012-02-24 17:08:13 +00:00
|
|
|
$objWriter->startElement('c:bubbleScale');
|
|
|
|
$objWriter->writeAttribute('val', 25 );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showNegBubbles');
|
|
|
|
$objWriter->writeAttribute('val', 0 );
|
|
|
|
$objWriter->endElement();
|
2012-03-04 11:30:33 +00:00
|
|
|
} elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) {
|
2012-02-29 22:01:45 +00:00
|
|
|
|
|
|
|
$objWriter->startElement('c:hiLowLines');
|
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 23:49:45 +00:00
|
|
|
// Generate 2 unique numbers to use for axId values
|
2012-03-04 11:30:33 +00:00
|
|
|
// $id1 = $id2 = rand(10000000,99999999);
|
|
|
|
// do {
|
|
|
|
// $id2 = rand(10000000,99999999);
|
|
|
|
// } while ($id1 == $id2);
|
|
|
|
$id1 = '75091328';
|
|
|
|
$id2 = '75089408';
|
2012-02-23 23:49:45 +00:00
|
|
|
|
2012-03-04 11:30:33 +00:00
|
|
|
if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
|
|
|
($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
|
|
|
($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
2012-02-23 17:20:25 +00:00
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:axId');
|
|
|
|
$objWriter->writeAttribute('val', $id1 );
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->startElement('c:axId');
|
|
|
|
$objWriter->writeAttribute('val', $id2 );
|
|
|
|
$objWriter->endElement();
|
|
|
|
} else {
|
|
|
|
$objWriter->startElement('c:firstSliceAng');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
2012-02-24 07:45:08 +00:00
|
|
|
|
2012-03-04 11:30:33 +00:00
|
|
|
if ($chartType === PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) {
|
2012-02-24 07:45:08 +00:00
|
|
|
|
|
|
|
$objWriter->startElement('c:holeSize');
|
|
|
|
$objWriter->writeAttribute('val', 50);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-04 11:30:33 +00:00
|
|
|
if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
|
|
|
($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
|
|
|
($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-03-04 11:30:33 +00:00
|
|
|
if ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
|
$this->_writeValAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries);
|
2012-02-24 17:08:13 +00:00
|
|
|
} else {
|
2012-03-04 11:30:33 +00:00
|
|
|
$this->_writeCatAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries);
|
2012-02-24 17:08:13 +00:00
|
|
|
}
|
2012-02-23 23:49:45 +00:00
|
|
|
|
2012-03-04 11:30:33 +00:00
|
|
|
$this->_writeValAx($objWriter,$plotArea,$yAxisLabel,$chartType,$id1,$id2,$valIsMultiLevelSeries);
|
2012-02-23 23:49:45 +00:00
|
|
|
}
|
2012-02-20 20:49:25 +00:00
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Data Labels
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-09-17 22:23:55 +00:00
|
|
|
* @param PHPExcel_Chart_Layout $chartLayout Chart layout
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-09-17 22:23:55 +00:00
|
|
|
private function _writeDataLbls($objWriter, $chartLayout)
|
2012-02-20 20:49:25 +00:00
|
|
|
{
|
|
|
|
$objWriter->startElement('c:dLbls');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showLegendKey');
|
2012-09-17 22:23:55 +00:00
|
|
|
$showLegendKey = (empty($chartLayout)) ? 0 : $chartLayout->getShowLegendKey();
|
|
|
|
$objWriter->writeAttribute('val', ((empty($showLegendKey)) ? 0 : 1) );
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-09-17 22:23:55 +00:00
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:showVal');
|
2012-09-17 22:23:55 +00:00
|
|
|
$showVal = (empty($chartLayout)) ? 0 : $chartLayout->getShowVal();
|
|
|
|
$objWriter->writeAttribute('val', ((empty($showVal)) ? 0 : 1) );
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showCatName');
|
2012-09-17 22:23:55 +00:00
|
|
|
$showCatName = (empty($chartLayout)) ? 0 : $chartLayout->getShowCatName();
|
|
|
|
$objWriter->writeAttribute('val', ((empty($showCatName)) ? 0 : 1) );
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showSerName');
|
2012-09-17 22:23:55 +00:00
|
|
|
$showSerName = (empty($chartLayout)) ? 0 : $chartLayout->getShowSerName();
|
|
|
|
$objWriter->writeAttribute('val', ((empty($showSerName)) ? 0 : 1) );
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showPercent');
|
2012-09-17 22:23:55 +00:00
|
|
|
$showPercent = (empty($chartLayout)) ? 0 : $chartLayout->getShowPercent();
|
|
|
|
$objWriter->writeAttribute('val', ((empty($showPercent)) ? 0 : 1) );
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showBubbleSize');
|
2012-09-17 22:23:55 +00:00
|
|
|
$showBubbleSize = (empty($chartLayout)) ? 0 : $chartLayout->getShowBubbleSize();
|
|
|
|
$objWriter->writeAttribute('val', ((empty($showBubbleSize)) ? 0 : 1) );
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:showLeaderLines');
|
2012-09-17 22:23:55 +00:00
|
|
|
$showLeaderLines = (empty($chartLayout)) ? 1 : $chartLayout->getShowLeaderLines();
|
|
|
|
$objWriter->writeAttribute('val', ((empty($showLeaderLines)) ? 0 : 1) );
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Category Axis
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
|
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
|
* @param PHPExcel_Chart_Title $xAxisLabel
|
|
|
|
* @param string $groupType Chart type
|
|
|
|
* @param string $id1
|
|
|
|
* @param string $id2
|
|
|
|
* @param boolean $isMultiLevelSeries
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-23 23:49:45 +00:00
|
|
|
private function _writeCatAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries)
|
2012-02-20 20:49:25 +00:00
|
|
|
{
|
|
|
|
$objWriter->startElement('c:catAx');
|
|
|
|
|
|
|
|
if ($id1 > 0) {
|
|
|
|
$objWriter->startElement('c:axId');
|
|
|
|
$objWriter->writeAttribute('val', $id1);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->startElement('c:scaling');
|
|
|
|
$objWriter->startElement('c:orientation');
|
|
|
|
$objWriter->writeAttribute('val', "minMax");
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:delete');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:axPos');
|
|
|
|
$objWriter->writeAttribute('val', "b");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-02-23 17:20:25 +00:00
|
|
|
if (!is_null($xAxisLabel)) {
|
|
|
|
$objWriter->startElement('c:title');
|
|
|
|
$objWriter->startElement('c:tx');
|
|
|
|
$objWriter->startElement('c:rich');
|
|
|
|
|
|
|
|
$objWriter->startElement('a:bodyPr');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('a:lstStyle');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('a:p');
|
|
|
|
$objWriter->startElement('a:r');
|
|
|
|
|
|
|
|
$caption = $xAxisLabel->getCaption();
|
|
|
|
if (is_array($caption))
|
|
|
|
$caption = $caption[0];
|
|
|
|
$objWriter->startElement('a:t');
|
2012-08-04 15:08:28 +00:00
|
|
|
// $objWriter->writeAttribute('xml:space', 'preserve');
|
2012-02-23 17:20:25 +00:00
|
|
|
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-10-26 23:02:38 +00:00
|
|
|
$layout = $xAxisLabel->getLayout();
|
|
|
|
$this->_writeLayout($layout, $objWriter);
|
|
|
|
|
2012-02-23 17:20:25 +00:00
|
|
|
$objWriter->startElement('c:overlay');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:numFmt');
|
|
|
|
$objWriter->writeAttribute('formatCode', "General");
|
|
|
|
$objWriter->writeAttribute('sourceLinked', 1);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:majorTickMark');
|
|
|
|
$objWriter->writeAttribute('val', "out");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:minorTickMark');
|
|
|
|
$objWriter->writeAttribute('val', "none");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:tickLblPos');
|
|
|
|
$objWriter->writeAttribute('val', "nextTo");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
if ($id2 > 0) {
|
2012-02-23 23:49:45 +00:00
|
|
|
$objWriter->startElement('c:crossAx');
|
|
|
|
$objWriter->writeAttribute('val', $id2);
|
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-02-23 23:49:45 +00:00
|
|
|
$objWriter->startElement('c:crosses');
|
|
|
|
$objWriter->writeAttribute('val', "autoZero");
|
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->startElement('c:auto');
|
|
|
|
$objWriter->writeAttribute('val', 1);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:lblAlgn');
|
|
|
|
$objWriter->writeAttribute('val', "ctr");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:lblOffset');
|
|
|
|
$objWriter->writeAttribute('val', 100);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
if ($isMultiLevelSeries) {
|
|
|
|
$objWriter->startElement('c:noMultiLvlLbl');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Value Axis
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
|
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
|
* @param PHPExcel_Chart_Title $yAxisLabel
|
|
|
|
* @param string $groupType Chart type
|
|
|
|
* @param string $id1
|
|
|
|
* @param string $id2
|
|
|
|
* @param boolean $isMultiLevelSeries
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-23 23:49:45 +00:00
|
|
|
private function _writeValAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries)
|
2012-02-20 20:49:25 +00:00
|
|
|
{
|
|
|
|
$objWriter->startElement('c:valAx');
|
|
|
|
|
|
|
|
if ($id2 > 0) {
|
|
|
|
$objWriter->startElement('c:axId');
|
|
|
|
$objWriter->writeAttribute('val', $id2);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->startElement('c:scaling');
|
|
|
|
$objWriter->startElement('c:orientation');
|
|
|
|
$objWriter->writeAttribute('val', "minMax");
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:delete');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:axPos');
|
|
|
|
$objWriter->writeAttribute('val', "l");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:majorGridlines');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
if (!is_null($yAxisLabel)) {
|
|
|
|
$objWriter->startElement('c:title');
|
|
|
|
$objWriter->startElement('c:tx');
|
|
|
|
$objWriter->startElement('c:rich');
|
2012-02-23 17:20:25 +00:00
|
|
|
|
|
|
|
$objWriter->startElement('a:bodyPr');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('a:lstStyle');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('a:p');
|
2012-02-23 17:20:25 +00:00
|
|
|
$objWriter->startElement('a:r');
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-02-23 17:20:25 +00:00
|
|
|
$caption = $yAxisLabel->getCaption();
|
|
|
|
if (is_array($caption))
|
|
|
|
$caption = $caption[0];
|
|
|
|
$objWriter->startElement('a:t');
|
2012-08-04 15:08:28 +00:00
|
|
|
// $objWriter->writeAttribute('xml:space', 'preserve');
|
2012-02-23 17:20:25 +00:00
|
|
|
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
|
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-02-23 17:20:25 +00:00
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-02-24 23:58:02 +00:00
|
|
|
if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
|
$layout = $yAxisLabel->getLayout();
|
|
|
|
$this->_writeLayout($layout, $objWriter);
|
|
|
|
}
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-10-26 23:02:38 +00:00
|
|
|
$objWriter->startElement('c:overlay');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-02-23 17:20:25 +00:00
|
|
|
$objWriter->startElement('c:numFmt');
|
|
|
|
$objWriter->writeAttribute('formatCode', "General");
|
|
|
|
$objWriter->writeAttribute('sourceLinked', 1);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:majorTickMark');
|
|
|
|
$objWriter->writeAttribute('val', "out");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:minorTickMark');
|
|
|
|
$objWriter->writeAttribute('val', "none");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:tickLblPos');
|
|
|
|
$objWriter->writeAttribute('val', "nextTo");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
if ($id1 > 0) {
|
2012-02-23 23:49:45 +00:00
|
|
|
$objWriter->startElement('c:crossAx');
|
|
|
|
$objWriter->writeAttribute('val', $id2);
|
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-02-23 23:49:45 +00:00
|
|
|
$objWriter->startElement('c:crosses');
|
|
|
|
$objWriter->writeAttribute('val', "autoZero");
|
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
|
2012-02-23 23:49:45 +00:00
|
|
|
$objWriter->startElement('c:crossBetween');
|
|
|
|
$objWriter->writeAttribute('val', "midCat");
|
|
|
|
$objWriter->endElement();
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($isMultiLevelSeries) {
|
2012-02-24 17:08:13 +00:00
|
|
|
if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
|
|
|
$objWriter->startElement('c:noMultiLvlLbl');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Get the data series type(s) for a chart plot series
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_PlotArea $plotArea
|
|
|
|
* @return string|array
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private static function _getChartType($plotArea)
|
|
|
|
{
|
|
|
|
$groupCount = $plotArea->getPlotGroupCount();
|
2012-02-29 22:01:45 +00:00
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
if ($groupCount == 1) {
|
|
|
|
$chartType = array($plotArea->getPlotGroupByIndex(0)->getPlotType());
|
|
|
|
} else {
|
|
|
|
$chartTypes = array();
|
|
|
|
for($i = 0; $i < $groupCount; ++$i) {
|
|
|
|
$chartTypes[] = $plotArea->getPlotGroupByIndex($i)->getPlotType();
|
|
|
|
}
|
|
|
|
$chartType = array_unique($chartTypes);
|
|
|
|
if (count($chartTypes) == 0) {
|
2012-11-05 23:34:02 +00:00
|
|
|
throw new PHPExcel_Writer_Exception('Chart is not yet implemented');
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $chartType;
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Plot Group (series of related plots)
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_DataSeries $plotGroup
|
|
|
|
* @param string $groupType Type of plot for dataseries
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
|
* @param boolean &$catIsMultiLevelSeries Is category a multi-series category
|
|
|
|
* @param boolean &$valIsMultiLevelSeries Is value set a multi-series set
|
|
|
|
* @param string &$plotGroupingType Type of grouping for multi-series values
|
2012-07-20 22:13:16 +00:00
|
|
|
* @param PHPExcel_Worksheet $pSheet
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-07-20 22:13:16 +00:00
|
|
|
private function _writePlotGroup( $plotGroup,
|
|
|
|
$groupType,
|
|
|
|
$objWriter,
|
|
|
|
&$catIsMultiLevelSeries,
|
|
|
|
&$valIsMultiLevelSeries,
|
|
|
|
&$plotGroupingType,
|
|
|
|
PHPExcel_Worksheet $pSheet
|
|
|
|
)
|
2012-02-20 20:49:25 +00:00
|
|
|
{
|
|
|
|
if (is_null($plotGroup)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
|
|
|
($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
|
|
|
|
$objWriter->startElement('c:barDir');
|
|
|
|
$objWriter->writeAttribute('val', $plotGroup->getPlotDirection());
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($plotGroup->getPlotGrouping())) {
|
2012-02-24 13:30:22 +00:00
|
|
|
$plotGroupingType = $plotGroup->getPlotGrouping();
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:grouping');
|
2012-02-24 13:30:22 +00:00
|
|
|
$objWriter->writeAttribute('val', $plotGroupingType);
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-02-24 13:13:38 +00:00
|
|
|
// Get these details before the loop, because we can use the count to check for varyColors
|
2012-02-20 20:49:25 +00:00
|
|
|
$plotSeriesOrder = $plotGroup->getPlotOrder();
|
|
|
|
$plotSeriesCount = count($plotSeriesOrder);
|
2012-02-24 13:13:38 +00:00
|
|
|
|
2012-02-26 12:31:03 +00:00
|
|
|
if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_RADARCHART) &&
|
2012-02-24 13:13:38 +00:00
|
|
|
($groupType !== PHPExcel_Chart_DataSeries::TYPE_STOCKCHART)) {
|
|
|
|
|
2012-03-04 11:30:33 +00:00
|
|
|
if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
|
|
|
|
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
|
|
|
|
($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
|
|
|
|
($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) ||
|
|
|
|
($plotSeriesCount > 1)) {
|
|
|
|
$objWriter->startElement('c:varyColors');
|
|
|
|
$objWriter->writeAttribute('val', 1);
|
|
|
|
$objWriter->endElement();
|
|
|
|
} else {
|
|
|
|
$objWriter->startElement('c:varyColors');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
2012-02-24 13:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
foreach($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
|
|
|
|
$objWriter->startElement('c:ser');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:idx');
|
2013-02-19 12:23:38 +00:00
|
|
|
$objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx);
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:order');
|
2013-02-19 12:23:38 +00:00
|
|
|
$objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesRef);
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
|
|
|
|
($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
|
|
|
|
($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
2012-02-24 17:08:13 +00:00
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->startElement('c:dPt');
|
|
|
|
$objWriter->startElement('c:idx');
|
|
|
|
$objWriter->writeAttribute('val', 3);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:bubble3D');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:spPr');
|
|
|
|
$objWriter->startElement('a:solidFill');
|
|
|
|
$objWriter->startElement('a:srgbClr');
|
|
|
|
$objWriter->writeAttribute('val', 'FF9900');
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Labels
|
|
|
|
$plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef);
|
|
|
|
if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) {
|
|
|
|
$objWriter->startElement('c:tx');
|
|
|
|
$objWriter->startElement('c:strRef');
|
|
|
|
$this->_writePlotSeriesLabel($plotSeriesLabel, $objWriter);
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Formatting for the points
|
|
|
|
if ($groupType == PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
|
|
|
|
$objWriter->startElement('c:spPr');
|
|
|
|
$objWriter->startElement('a:ln');
|
|
|
|
$objWriter->writeAttribute('w', 12700);
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-02-26 13:42:36 +00:00
|
|
|
$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
|
|
|
|
if ($plotSeriesValues) {
|
|
|
|
$plotSeriesMarker = $plotSeriesValues->getPointMarker();
|
|
|
|
if ($plotSeriesMarker) {
|
|
|
|
$objWriter->startElement('c:marker');
|
|
|
|
$objWriter->startElement('c:symbol');
|
|
|
|
$objWriter->writeAttribute('val', $plotSeriesMarker);
|
|
|
|
$objWriter->endElement();
|
2012-02-29 22:01:45 +00:00
|
|
|
|
|
|
|
if ($plotSeriesMarker !== 'none') {
|
|
|
|
$objWriter->startElement('c:size');
|
|
|
|
$objWriter->writeAttribute('val', 3);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
2012-02-26 12:31:03 +00:00
|
|
|
$objWriter->endElement();
|
2012-02-26 13:42:36 +00:00
|
|
|
}
|
2012-02-26 12:31:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 17:20:25 +00:00
|
|
|
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
2012-02-24 23:58:02 +00:00
|
|
|
($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D) ||
|
|
|
|
($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART)) {
|
2012-02-20 20:49:25 +00:00
|
|
|
|
|
|
|
$objWriter->startElement('c:invertIfNegative');
|
|
|
|
$objWriter->writeAttribute('val', 0);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Category Labels
|
|
|
|
$plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef);
|
|
|
|
if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) {
|
|
|
|
$catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries();
|
2012-02-24 17:08:13 +00:00
|
|
|
|
|
|
|
if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
|
|
|
|
($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
|
|
|
|
($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
|
|
|
|
|
|
if (!is_null($plotGroup->getPlotStyle())) {
|
|
|
|
$plotStyle = $plotGroup->getPlotStyle();
|
|
|
|
if ($plotStyle) {
|
|
|
|
$objWriter->startElement('c:explosion');
|
|
|
|
$objWriter->writeAttribute('val', 25);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-26 12:31:03 +00:00
|
|
|
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) ||
|
|
|
|
($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) {
|
2012-02-24 17:08:13 +00:00
|
|
|
$objWriter->startElement('c:xVal');
|
|
|
|
} else {
|
|
|
|
$objWriter->startElement('c:cat');
|
|
|
|
}
|
|
|
|
|
2012-07-20 22:13:16 +00:00
|
|
|
$this->_writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str', $pSheet);
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Values
|
|
|
|
if ($plotSeriesValues) {
|
|
|
|
$valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries();
|
2012-02-24 17:08:13 +00:00
|
|
|
|
2012-02-26 12:31:03 +00:00
|
|
|
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) ||
|
|
|
|
($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) {
|
2012-02-24 17:08:13 +00:00
|
|
|
$objWriter->startElement('c:yVal');
|
|
|
|
} else {
|
|
|
|
$objWriter->startElement('c:val');
|
|
|
|
}
|
|
|
|
|
2012-07-20 22:13:16 +00:00
|
|
|
$this->_writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num', $pSheet);
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-02-24 23:58:02 +00:00
|
|
|
if ($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
|
2012-07-20 22:53:16 +00:00
|
|
|
$this->_writeBubbles($plotSeriesValues, $objWriter, $pSheet);
|
2012-02-24 23:58:02 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 20:49:25 +00:00
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
}
|
2013-02-19 12:23:38 +00:00
|
|
|
|
|
|
|
$this->_seriesIndex += $plotSeriesIdx + 1;
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Plot Series Label
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_DataSeriesValues $plotSeriesLabel
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private function _writePlotSeriesLabel($plotSeriesLabel, $objWriter)
|
|
|
|
{
|
|
|
|
if (is_null($plotSeriesLabel)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->startElement('c:f');
|
|
|
|
$objWriter->writeRawData($plotSeriesLabel->getDataSource());
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:strCache');
|
|
|
|
$objWriter->startElement('c:ptCount');
|
|
|
|
$objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount() );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
foreach($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) {
|
|
|
|
$objWriter->startElement('c:pt');
|
|
|
|
$objWriter->writeAttribute('idx', $plotLabelKey );
|
|
|
|
|
|
|
|
$objWriter->startElement('c:v');
|
|
|
|
$objWriter->writeRawData( $plotLabelValue );
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Plot Series Values
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
|
|
|
* @param string $groupType Type of plot for dataseries
|
|
|
|
* @param string $dataType Datatype of series values
|
2012-07-20 22:13:16 +00:00
|
|
|
* @param PHPExcel_Worksheet $pSheet
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-07-20 22:13:16 +00:00
|
|
|
private function _writePlotSeriesValues( $plotSeriesValues,
|
|
|
|
$objWriter,
|
|
|
|
$groupType,
|
|
|
|
$dataType='str',
|
|
|
|
PHPExcel_Worksheet $pSheet
|
|
|
|
)
|
2012-02-20 20:49:25 +00:00
|
|
|
{
|
|
|
|
if (is_null($plotSeriesValues)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($plotSeriesValues->isMultiLevelSeries()) {
|
|
|
|
$levelCount = $plotSeriesValues->multiLevelCount();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:multiLvlStrRef');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:f');
|
|
|
|
$objWriter->writeRawData( $plotSeriesValues->getDataSource() );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:multiLvlStrCache');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:ptCount');
|
|
|
|
$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
for ($level = 0; $level < $levelCount; ++$level) {
|
|
|
|
$objWriter->startElement('c:lvl');
|
|
|
|
|
|
|
|
foreach($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
|
|
|
|
if (isset($plotSeriesValue[$level])) {
|
|
|
|
$objWriter->startElement('c:pt');
|
|
|
|
$objWriter->writeAttribute('idx', $plotSeriesKey );
|
|
|
|
|
|
|
|
$objWriter->startElement('c:v');
|
|
|
|
$objWriter->writeRawData( $plotSeriesValue[$level] );
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
} else {
|
|
|
|
$objWriter->startElement('c:'.$dataType.'Ref');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:f');
|
|
|
|
$objWriter->writeRawData( $plotSeriesValues->getDataSource() );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:'.$dataType.'Cache');
|
|
|
|
|
2012-02-23 23:49:45 +00:00
|
|
|
if (($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
|
|
|
($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
|
|
|
($groupType != PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
|
|
|
2012-07-27 11:22:47 +00:00
|
|
|
if (($plotSeriesValues->getFormatCode() !== NULL) &&
|
|
|
|
($plotSeriesValues->getFormatCode() !== '')) {
|
2012-03-28 12:02:24 +00:00
|
|
|
$objWriter->startElement('c:formatCode');
|
|
|
|
$objWriter->writeRawData( $plotSeriesValues->getFormatCode() );
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
2012-02-23 23:49:45 +00:00
|
|
|
}
|
2012-02-20 20:49:25 +00:00
|
|
|
|
|
|
|
$objWriter->startElement('c:ptCount');
|
|
|
|
$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-07-14 00:26:53 +00:00
|
|
|
$dataValues = $plotSeriesValues->getDataValues();
|
|
|
|
if (!empty($dataValues)) {
|
2012-07-20 21:35:53 +00:00
|
|
|
if (is_array($dataValues)) {
|
|
|
|
foreach($dataValues as $plotSeriesKey => $plotSeriesValue) {
|
|
|
|
$objWriter->startElement('c:pt');
|
|
|
|
$objWriter->writeAttribute('idx', $plotSeriesKey );
|
2012-07-14 00:26:53 +00:00
|
|
|
|
2012-07-20 21:35:53 +00:00
|
|
|
$objWriter->startElement('c:v');
|
|
|
|
$objWriter->writeRawData( $plotSeriesValue );
|
|
|
|
$objWriter->endElement();
|
2012-07-14 00:26:53 +00:00
|
|
|
$objWriter->endElement();
|
2012-07-20 21:35:53 +00:00
|
|
|
}
|
2012-07-14 00:26:53 +00:00
|
|
|
}
|
2012-02-20 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Bubble Chart Details
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-07-20 22:53:16 +00:00
|
|
|
private function _writeBubbles($plotSeriesValues, $objWriter, PHPExcel_Worksheet $pSheet)
|
2012-02-24 23:58:02 +00:00
|
|
|
{
|
|
|
|
if (is_null($plotSeriesValues)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->startElement('c:bubbleSize');
|
|
|
|
$objWriter->startElement('c:numLit');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:formatCode');
|
|
|
|
$objWriter->writeRawData( 'General' );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:ptCount');
|
|
|
|
$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
2012-07-20 22:53:16 +00:00
|
|
|
$dataValues = $plotSeriesValues->getDataValues();
|
|
|
|
if (!empty($dataValues)) {
|
|
|
|
if (is_array($dataValues)) {
|
|
|
|
foreach($dataValues as $plotSeriesKey => $plotSeriesValue) {
|
|
|
|
$objWriter->startElement('c:pt');
|
|
|
|
$objWriter->writeAttribute('idx', $plotSeriesKey );
|
|
|
|
$objWriter->startElement('c:v');
|
|
|
|
$objWriter->writeRawData( 1 );
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
}
|
2012-02-24 23:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:bubble3D');
|
|
|
|
$objWriter->writeAttribute('val', 0 );
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Layout
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Chart_Layout $layout
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private function _writeLayout(PHPExcel_Chart_Layout $layout = NULL, $objWriter)
|
|
|
|
{
|
|
|
|
$objWriter->startElement('c:layout');
|
|
|
|
|
|
|
|
if (!is_null($layout)) {
|
|
|
|
$objWriter->startElement('c:manualLayout');
|
|
|
|
|
|
|
|
$layoutTarget = $layout->getLayoutTarget();
|
|
|
|
if (!is_null($layoutTarget)) {
|
|
|
|
$objWriter->startElement('c:layoutTarget');
|
|
|
|
$objWriter->writeAttribute('val', $layoutTarget);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$xMode = $layout->getXMode();
|
|
|
|
if (!is_null($xMode)) {
|
|
|
|
$objWriter->startElement('c:xMode');
|
|
|
|
$objWriter->writeAttribute('val', $xMode);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$yMode = $layout->getYMode();
|
|
|
|
if (!is_null($yMode)) {
|
|
|
|
$objWriter->startElement('c:yMode');
|
|
|
|
$objWriter->writeAttribute('val', $yMode);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$x = $layout->getXPosition();
|
|
|
|
if (!is_null($x)) {
|
|
|
|
$objWriter->startElement('c:x');
|
|
|
|
$objWriter->writeAttribute('val', $x);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$y = $layout->getYPosition();
|
|
|
|
if (!is_null($y)) {
|
|
|
|
$objWriter->startElement('c:y');
|
|
|
|
$objWriter->writeAttribute('val', $y);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$w = $layout->getWidth();
|
|
|
|
if (!is_null($w)) {
|
|
|
|
$objWriter->startElement('c:w');
|
|
|
|
$objWriter->writeAttribute('val', $w);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$h = $layout->getHeight();
|
|
|
|
if (!is_null($h)) {
|
|
|
|
$objWriter->startElement('c:h');
|
|
|
|
$objWriter->writeAttribute('val', $h);
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Alternate Content block
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private function _writeAlternateContent($objWriter)
|
|
|
|
{
|
|
|
|
$objWriter->startElement('mc:AlternateContent');
|
|
|
|
$objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
|
|
|
|
|
|
|
|
$objWriter->startElement('mc:Choice');
|
|
|
|
$objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart');
|
|
|
|
$objWriter->writeAttribute('Requires', 'c14');
|
|
|
|
|
|
|
|
$objWriter->startElement('c14:style');
|
|
|
|
$objWriter->writeAttribute('val', '102');
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('mc:Fallback');
|
|
|
|
$objWriter->startElement('c:style');
|
|
|
|
$objWriter->writeAttribute('val', '2');
|
|
|
|
$objWriter->endElement();
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:58:38 +00:00
|
|
|
/**
|
|
|
|
* Write Printer Settings
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
|
2012-11-05 23:34:02 +00:00
|
|
|
* @throws PHPExcel_Writer_Exception
|
2012-03-11 17:58:38 +00:00
|
|
|
*/
|
2012-02-20 20:49:25 +00:00
|
|
|
private function _writePrintSettings($objWriter)
|
|
|
|
{
|
|
|
|
$objWriter->startElement('c:printSettings');
|
|
|
|
|
|
|
|
$objWriter->startElement('c:headerFooter');
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:pageMargins');
|
|
|
|
$objWriter->writeAttribute('footer', 0.3);
|
|
|
|
$objWriter->writeAttribute('header', 0.3);
|
|
|
|
$objWriter->writeAttribute('r', 0.7);
|
|
|
|
$objWriter->writeAttribute('l', 0.7);
|
|
|
|
$objWriter->writeAttribute('t', 0.75);
|
|
|
|
$objWriter->writeAttribute('b', 0.75);
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->startElement('c:pageSetup');
|
|
|
|
$objWriter->writeAttribute('orientation', "portrait");
|
|
|
|
$objWriter->endElement();
|
|
|
|
|
|
|
|
$objWriter->endElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|