44a03fefcfaec99014b74786105c3a4a705dd70c.svn-base 56 KB

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