e786e9bb4be33c2b406038c526491d8b5220cbda.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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_Chart
  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_Chart
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Chart
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Chart
  35. {
  36. /**
  37. * Chart Name
  38. *
  39. * @var string
  40. */
  41. private $_name = '';
  42. /**
  43. * Worksheet
  44. *
  45. * @var PHPExcel_Worksheet
  46. */
  47. private $_worksheet = null;
  48. /**
  49. * Chart Title
  50. *
  51. * @var PHPExcel_Chart_Title
  52. */
  53. private $_title = null;
  54. /**
  55. * Chart Legend
  56. *
  57. * @var PHPExcel_Chart_Legend
  58. */
  59. private $_legend = null;
  60. /**
  61. * X-Axis Label
  62. *
  63. * @var PHPExcel_Chart_Title
  64. */
  65. private $_xAxisLabel = null;
  66. /**
  67. * Y-Axis Label
  68. *
  69. * @var PHPExcel_Chart_Title
  70. */
  71. private $_yAxisLabel = null;
  72. /**
  73. * Chart Plot Area
  74. *
  75. * @var PHPExcel_Chart_PlotArea
  76. */
  77. private $_plotArea = null;
  78. /**
  79. * Plot Visible Only
  80. *
  81. * @var boolean
  82. */
  83. private $_plotVisibleOnly = true;
  84. /**
  85. * Display Blanks as
  86. *
  87. * @var string
  88. */
  89. private $_displayBlanksAs = '0';
  90. /**
  91. * Chart Asix Y as
  92. *
  93. * @var PHPExcel_Chart_Axis
  94. */
  95. private $_yAxis = null;
  96. /**
  97. * Chart Asix X as
  98. *
  99. * @var PHPExcel_Chart_Axis
  100. */
  101. private $_xAxis = null;
  102. /**
  103. * Chart Major Gridlines as
  104. *
  105. * @var PHPExcel_Chart_GridLines
  106. */
  107. private $_majorGridlines = null;
  108. /**
  109. * Chart Minor Gridlines as
  110. *
  111. * @var PHPExcel_Chart_GridLines
  112. */
  113. private $_minorGridlines = null;
  114. /**
  115. * Top-Left Cell Position
  116. *
  117. * @var string
  118. */
  119. private $_topLeftCellRef = 'A1';
  120. /**
  121. * Top-Left X-Offset
  122. *
  123. * @var integer
  124. */
  125. private $_topLeftXOffset = 0;
  126. /**
  127. * Top-Left Y-Offset
  128. *
  129. * @var integer
  130. */
  131. private $_topLeftYOffset = 0;
  132. /**
  133. * Bottom-Right Cell Position
  134. *
  135. * @var string
  136. */
  137. private $_bottomRightCellRef = 'A1';
  138. /**
  139. * Bottom-Right X-Offset
  140. *
  141. * @var integer
  142. */
  143. private $_bottomRightXOffset = 10;
  144. /**
  145. * Bottom-Right Y-Offset
  146. *
  147. * @var integer
  148. */
  149. private $_bottomRightYOffset = 10;
  150. /**
  151. * Create a new PHPExcel_Chart
  152. */
  153. public function __construct($name, PHPExcel_Chart_Title $title = null, PHPExcel_Chart_Legend $legend = null, PHPExcel_Chart_PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = '0', PHPExcel_Chart_Title $xAxisLabel = null, PHPExcel_Chart_Title $yAxisLabel = null, PHPExcel_Chart_Axis $xAxis = null, PHPExcel_Chart_Axis $yAxis = null, PHPExcel_Chart_GridLines $majorGridlines = null, PHPExcel_Chart_GridLines $minorGridlines = null)
  154. {
  155. $this->_name = $name;
  156. $this->_title = $title;
  157. $this->_legend = $legend;
  158. $this->_xAxisLabel = $xAxisLabel;
  159. $this->_yAxisLabel = $yAxisLabel;
  160. $this->_plotArea = $plotArea;
  161. $this->_plotVisibleOnly = $plotVisibleOnly;
  162. $this->_displayBlanksAs = $displayBlanksAs;
  163. $this->_xAxis = $xAxis;
  164. $this->_yAxis = $yAxis;
  165. $this->_majorGridlines = $majorGridlines;
  166. $this->_minorGridlines = $minorGridlines;
  167. }
  168. /**
  169. * Get Name
  170. *
  171. * @return string
  172. */
  173. public function getName() {
  174. return $this->_name;
  175. }
  176. /**
  177. * Get Worksheet
  178. *
  179. * @return PHPExcel_Worksheet
  180. */
  181. public function getWorksheet() {
  182. return $this->_worksheet;
  183. }
  184. /**
  185. * Set Worksheet
  186. *
  187. * @param PHPExcel_Worksheet $pValue
  188. * @throws PHPExcel_Chart_Exception
  189. * @return PHPExcel_Chart
  190. */
  191. public function setWorksheet(PHPExcel_Worksheet $pValue = null) {
  192. $this->_worksheet = $pValue;
  193. return $this;
  194. }
  195. /**
  196. * Get Title
  197. *
  198. * @return PHPExcel_Chart_Title
  199. */
  200. public function getTitle() {
  201. return $this->_title;
  202. }
  203. /**
  204. * Set Title
  205. *
  206. * @param PHPExcel_Chart_Title $title
  207. * @return PHPExcel_Chart
  208. */
  209. public function setTitle(PHPExcel_Chart_Title $title) {
  210. $this->_title = $title;
  211. return $this;
  212. }
  213. /**
  214. * Get Legend
  215. *
  216. * @return PHPExcel_Chart_Legend
  217. */
  218. public function getLegend() {
  219. return $this->_legend;
  220. }
  221. /**
  222. * Set Legend
  223. *
  224. * @param PHPExcel_Chart_Legend $legend
  225. * @return PHPExcel_Chart
  226. */
  227. public function setLegend(PHPExcel_Chart_Legend $legend) {
  228. $this->_legend = $legend;
  229. return $this;
  230. }
  231. /**
  232. * Get X-Axis Label
  233. *
  234. * @return PHPExcel_Chart_Title
  235. */
  236. public function getXAxisLabel() {
  237. return $this->_xAxisLabel;
  238. }
  239. /**
  240. * Set X-Axis Label
  241. *
  242. * @param PHPExcel_Chart_Title $label
  243. * @return PHPExcel_Chart
  244. */
  245. public function setXAxisLabel(PHPExcel_Chart_Title $label) {
  246. $this->_xAxisLabel = $label;
  247. return $this;
  248. }
  249. /**
  250. * Get Y-Axis Label
  251. *
  252. * @return PHPExcel_Chart_Title
  253. */
  254. public function getYAxisLabel() {
  255. return $this->_yAxisLabel;
  256. }
  257. /**
  258. * Set Y-Axis Label
  259. *
  260. * @param PHPExcel_Chart_Title $label
  261. * @return PHPExcel_Chart
  262. */
  263. public function setYAxisLabel(PHPExcel_Chart_Title $label) {
  264. $this->_yAxisLabel = $label;
  265. return $this;
  266. }
  267. /**
  268. * Get Plot Area
  269. *
  270. * @return PHPExcel_Chart_PlotArea
  271. */
  272. public function getPlotArea() {
  273. return $this->_plotArea;
  274. }
  275. /**
  276. * Get Plot Visible Only
  277. *
  278. * @return boolean
  279. */
  280. public function getPlotVisibleOnly() {
  281. return $this->_plotVisibleOnly;
  282. }
  283. /**
  284. * Set Plot Visible Only
  285. *
  286. * @param boolean $plotVisibleOnly
  287. * @return PHPExcel_Chart
  288. */
  289. public function setPlotVisibleOnly($plotVisibleOnly = true) {
  290. $this->_plotVisibleOnly = $plotVisibleOnly;
  291. return $this;
  292. }
  293. /**
  294. * Get Display Blanks as
  295. *
  296. * @return string
  297. */
  298. public function getDisplayBlanksAs() {
  299. return $this->_displayBlanksAs;
  300. }
  301. /**
  302. * Set Display Blanks as
  303. *
  304. * @param string $displayBlanksAs
  305. * @return PHPExcel_Chart
  306. */
  307. public function setDisplayBlanksAs($displayBlanksAs = '0') {
  308. $this->_displayBlanksAs = $displayBlanksAs;
  309. }
  310. /**
  311. * Get yAxis
  312. *
  313. * @return PHPExcel_Chart_Axis
  314. */
  315. public function getChartAxisY() {
  316. if($this->_yAxis !== NULL){
  317. return $this->_yAxis;
  318. }
  319. return new PHPExcel_Chart_Axis();
  320. }
  321. /**
  322. * Get xAxis
  323. *
  324. * @return PHPExcel_Chart_Axis
  325. */
  326. public function getChartAxisX() {
  327. if($this->_xAxis !== NULL){
  328. return $this->_xAxis;
  329. }
  330. return new PHPExcel_Chart_Axis();
  331. }
  332. /**
  333. * Get Major Gridlines
  334. *
  335. * @return PHPExcel_Chart_GridLines
  336. */
  337. public function getMajorGridlines() {
  338. if($this->_majorGridlines !== NULL){
  339. return $this->_majorGridlines;
  340. }
  341. return new PHPExcel_Chart_GridLines();
  342. }
  343. /**
  344. * Get Minor Gridlines
  345. *
  346. * @return PHPExcel_Chart_GridLines
  347. */
  348. public function getMinorGridlines() {
  349. if($this->_minorGridlines !== NULL){
  350. return $this->_minorGridlines;
  351. }
  352. return new PHPExcel_Chart_GridLines();
  353. }
  354. /**
  355. * Set the Top Left position for the chart
  356. *
  357. * @param string $cell
  358. * @param integer $xOffset
  359. * @param integer $yOffset
  360. * @return PHPExcel_Chart
  361. */
  362. public function setTopLeftPosition($cell, $xOffset=null, $yOffset=null) {
  363. $this->_topLeftCellRef = $cell;
  364. if (!is_null($xOffset))
  365. $this->setTopLeftXOffset($xOffset);
  366. if (!is_null($yOffset))
  367. $this->setTopLeftYOffset($yOffset);
  368. return $this;
  369. }
  370. /**
  371. * Get the top left position of the chart
  372. *
  373. * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
  374. */
  375. public function getTopLeftPosition() {
  376. return array( 'cell' => $this->_topLeftCellRef,
  377. 'xOffset' => $this->_topLeftXOffset,
  378. 'yOffset' => $this->_topLeftYOffset
  379. );
  380. }
  381. /**
  382. * Get the cell address where the top left of the chart is fixed
  383. *
  384. * @return string
  385. */
  386. public function getTopLeftCell() {
  387. return $this->_topLeftCellRef;
  388. }
  389. /**
  390. * Set the Top Left cell position for the chart
  391. *
  392. * @param string $cell
  393. * @return PHPExcel_Chart
  394. */
  395. public function setTopLeftCell($cell) {
  396. $this->_topLeftCellRef = $cell;
  397. return $this;
  398. }
  399. /**
  400. * Set the offset position within the Top Left cell for the chart
  401. *
  402. * @param integer $xOffset
  403. * @param integer $yOffset
  404. * @return PHPExcel_Chart
  405. */
  406. public function setTopLeftOffset($xOffset=null,$yOffset=null) {
  407. if (!is_null($xOffset))
  408. $this->setTopLeftXOffset($xOffset);
  409. if (!is_null($yOffset))
  410. $this->setTopLeftYOffset($yOffset);
  411. return $this;
  412. }
  413. /**
  414. * Get the offset position within the Top Left cell for the chart
  415. *
  416. * @return integer[]
  417. */
  418. public function getTopLeftOffset() {
  419. return array( 'X' => $this->_topLeftXOffset,
  420. 'Y' => $this->_topLeftYOffset
  421. );
  422. }
  423. public function setTopLeftXOffset($xOffset) {
  424. $this->_topLeftXOffset = $xOffset;
  425. return $this;
  426. }
  427. public function getTopLeftXOffset() {
  428. return $this->_topLeftXOffset;
  429. }
  430. public function setTopLeftYOffset($yOffset) {
  431. $this->_topLeftYOffset = $yOffset;
  432. return $this;
  433. }
  434. public function getTopLeftYOffset() {
  435. return $this->_topLeftYOffset;
  436. }
  437. /**
  438. * Set the Bottom Right position of the chart
  439. *
  440. * @param string $cell
  441. * @param integer $xOffset
  442. * @param integer $yOffset
  443. * @return PHPExcel_Chart
  444. */
  445. public function setBottomRightPosition($cell, $xOffset=null, $yOffset=null) {
  446. $this->_bottomRightCellRef = $cell;
  447. if (!is_null($xOffset))
  448. $this->setBottomRightXOffset($xOffset);
  449. if (!is_null($yOffset))
  450. $this->setBottomRightYOffset($yOffset);
  451. return $this;
  452. }
  453. /**
  454. * Get the bottom right position of the chart
  455. *
  456. * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
  457. */
  458. public function getBottomRightPosition() {
  459. return array( 'cell' => $this->_bottomRightCellRef,
  460. 'xOffset' => $this->_bottomRightXOffset,
  461. 'yOffset' => $this->_bottomRightYOffset
  462. );
  463. }
  464. public function setBottomRightCell($cell) {
  465. $this->_bottomRightCellRef = $cell;
  466. return $this;
  467. }
  468. /**
  469. * Get the cell address where the bottom right of the chart is fixed
  470. *
  471. * @return string
  472. */
  473. public function getBottomRightCell() {
  474. return $this->_bottomRightCellRef;
  475. }
  476. /**
  477. * Set the offset position within the Bottom Right cell for the chart
  478. *
  479. * @param integer $xOffset
  480. * @param integer $yOffset
  481. * @return PHPExcel_Chart
  482. */
  483. public function setBottomRightOffset($xOffset=null,$yOffset=null) {
  484. if (!is_null($xOffset))
  485. $this->setBottomRightXOffset($xOffset);
  486. if (!is_null($yOffset))
  487. $this->setBottomRightYOffset($yOffset);
  488. return $this;
  489. }
  490. /**
  491. * Get the offset position within the Bottom Right cell for the chart
  492. *
  493. * @return integer[]
  494. */
  495. public function getBottomRightOffset() {
  496. return array( 'X' => $this->_bottomRightXOffset,
  497. 'Y' => $this->_bottomRightYOffset
  498. );
  499. }
  500. public function setBottomRightXOffset($xOffset) {
  501. $this->_bottomRightXOffset = $xOffset;
  502. return $this;
  503. }
  504. public function getBottomRightXOffset() {
  505. return $this->_bottomRightXOffset;
  506. }
  507. public function setBottomRightYOffset($yOffset) {
  508. $this->_bottomRightYOffset = $yOffset;
  509. return $this;
  510. }
  511. public function getBottomRightYOffset() {
  512. return $this->_bottomRightYOffset;
  513. }
  514. public function refresh() {
  515. if ($this->_worksheet !== NULL) {
  516. $this->_plotArea->refresh($this->_worksheet);
  517. }
  518. }
  519. public function render($outputDestination = null) {
  520. $libraryName = PHPExcel_Settings::getChartRendererName();
  521. if (is_null($libraryName)) {
  522. return false;
  523. }
  524. // Ensure that data series values are up-to-date before we render
  525. $this->refresh();
  526. $libraryPath = PHPExcel_Settings::getChartRendererPath();
  527. $includePath = str_replace('\\','/',get_include_path());
  528. $rendererPath = str_replace('\\','/',$libraryPath);
  529. if (strpos($rendererPath,$includePath) === false) {
  530. set_include_path(get_include_path() . PATH_SEPARATOR . $libraryPath);
  531. }
  532. $rendererName = 'PHPExcel_Chart_Renderer_'.$libraryName;
  533. $renderer = new $rendererName($this);
  534. if ($outputDestination == 'php://output') {
  535. $outputDestination = null;
  536. }
  537. return $renderer->render($outputDestination);
  538. }
  539. }