0
0

Chart.php 63 KB

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