5 * Copyright (c) 2006 - 2014 PHPExcel
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.
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.
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
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##
33 * @package PHPExcel_Chart
34 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
48 * @var PHPExcel_Worksheet
50 private $_worksheet = null;
55 * @var PHPExcel_Chart_Title
57 private $_title = null;
62 * @var PHPExcel_Chart_Legend
64 private $_legend = null;
69 * @var PHPExcel_Chart_Title
71 private $_xAxisLabel = null;
76 * @var PHPExcel_Chart_Title
78 private $_yAxisLabel = null;
83 * @var PHPExcel_Chart_PlotArea
85 private $_plotArea = null;
92 private $_plotVisibleOnly = true;
99 private $_displayBlanksAs = '0';
104 * @var PHPExcel_Chart_Axis
106 private $_yAxis = null;
111 * @var PHPExcel_Chart_Axis
113 private $_xAxis = null;
116 * Chart Major Gridlines as
118 * @var PHPExcel_Chart_GridLines
120 private $_majorGridlines = null;
123 * Chart Minor Gridlines as
125 * @var PHPExcel_Chart_GridLines
127 private $_minorGridlines = null;
130 * Top-Left Cell Position
134 private $_topLeftCellRef = 'A1';
142 private $_topLeftXOffset = 0;
150 private $_topLeftYOffset = 0;
154 * Bottom-Right Cell Position
158 private $_bottomRightCellRef = 'A1';
162 * Bottom-Right X-Offset
166 private $_bottomRightXOffset = 10;
170 * Bottom-Right Y-Offset
174 private $_bottomRightYOffset = 10;
178 * Create a new PHPExcel_Chart
180 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)
182 $this->_name
= $name;
183 $this->_title
= $title;
184 $this->_legend
= $legend;
185 $this->_xAxisLabel
= $xAxisLabel;
186 $this->_yAxisLabel
= $yAxisLabel;
187 $this->_plotArea
= $plotArea;
188 $this->_plotVisibleOnly
= $plotVisibleOnly;
189 $this->_displayBlanksAs
= $displayBlanksAs;
190 $this->_xAxis
= $xAxis;
191 $this->_yAxis
= $yAxis;
192 $this->_majorGridlines
= $majorGridlines;
193 $this->_minorGridlines
= $minorGridlines;
201 public function getName() {
208 * @return PHPExcel_Worksheet
210 public function getWorksheet() {
211 return $this->_worksheet
;
217 * @param PHPExcel_Worksheet $pValue
218 * @throws PHPExcel_Chart_Exception
219 * @return PHPExcel_Chart
221 public function setWorksheet(PHPExcel_Worksheet
$pValue = null) {
222 $this->_worksheet
= $pValue;
230 * @return PHPExcel_Chart_Title
232 public function getTitle() {
233 return $this->_title
;
239 * @param PHPExcel_Chart_Title $title
240 * @return PHPExcel_Chart
242 public function setTitle(PHPExcel_Chart_Title
$title) {
243 $this->_title
= $title;
251 * @return PHPExcel_Chart_Legend
253 public function getLegend() {
254 return $this->_legend
;
260 * @param PHPExcel_Chart_Legend $legend
261 * @return PHPExcel_Chart
263 public function setLegend(PHPExcel_Chart_Legend
$legend) {
264 $this->_legend
= $legend;
272 * @return PHPExcel_Chart_Title
274 public function getXAxisLabel() {
275 return $this->_xAxisLabel
;
281 * @param PHPExcel_Chart_Title $label
282 * @return PHPExcel_Chart
284 public function setXAxisLabel(PHPExcel_Chart_Title
$label) {
285 $this->_xAxisLabel
= $label;
293 * @return PHPExcel_Chart_Title
295 public function getYAxisLabel() {
296 return $this->_yAxisLabel
;
302 * @param PHPExcel_Chart_Title $label
303 * @return PHPExcel_Chart
305 public function setYAxisLabel(PHPExcel_Chart_Title
$label) {
306 $this->_yAxisLabel
= $label;
314 * @return PHPExcel_Chart_PlotArea
316 public function getPlotArea() {
317 return $this->_plotArea
;
321 * Get Plot Visible Only
325 public function getPlotVisibleOnly() {
326 return $this->_plotVisibleOnly
;
330 * Set Plot Visible Only
332 * @param boolean $plotVisibleOnly
333 * @return PHPExcel_Chart
335 public function setPlotVisibleOnly($plotVisibleOnly = true) {
336 $this->_plotVisibleOnly
= $plotVisibleOnly;
342 * Get Display Blanks as
346 public function getDisplayBlanksAs() {
347 return $this->_displayBlanksAs
;
351 * Set Display Blanks as
353 * @param string $displayBlanksAs
354 * @return PHPExcel_Chart
356 public function setDisplayBlanksAs($displayBlanksAs = '0') {
357 $this->_displayBlanksAs
= $displayBlanksAs;
364 * @return PHPExcel_Chart_Axis
366 public function getChartAxisY() {
367 if($this->_yAxis
!== NULL){
368 return $this->_yAxis
;
371 return new PHPExcel_Chart_Axis();
377 * @return PHPExcel_Chart_Axis
379 public function getChartAxisX() {
380 if($this->_xAxis
!== NULL){
381 return $this->_xAxis
;
384 return new PHPExcel_Chart_Axis();
388 * Get Major Gridlines
390 * @return PHPExcel_Chart_GridLines
392 public function getMajorGridlines() {
393 if($this->_majorGridlines
!== NULL){
394 return $this->_majorGridlines
;
397 return new PHPExcel_Chart_GridLines();
401 * Get Minor Gridlines
403 * @return PHPExcel_Chart_GridLines
405 public function getMinorGridlines() {
406 if($this->_minorGridlines
!== NULL){
407 return $this->_minorGridlines
;
410 return new PHPExcel_Chart_GridLines();
415 * Set the Top Left position for the chart
417 * @param string $cell
418 * @param integer $xOffset
419 * @param integer $yOffset
420 * @return PHPExcel_Chart
422 public function setTopLeftPosition($cell, $xOffset=null, $yOffset=null) {
423 $this->_topLeftCellRef
= $cell;
424 if (!is_null($xOffset))
425 $this->setTopLeftXOffset($xOffset);
426 if (!is_null($yOffset))
427 $this->setTopLeftYOffset($yOffset);
433 * Get the top left position of the chart
435 * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
437 public function getTopLeftPosition() {
438 return array( 'cell' => $this->_topLeftCellRef
,
439 'xOffset' => $this->_topLeftXOffset
,
440 'yOffset' => $this->_topLeftYOffset
445 * Get the cell address where the top left of the chart is fixed
449 public function getTopLeftCell() {
450 return $this->_topLeftCellRef
;
454 * Set the Top Left cell position for the chart
456 * @param string $cell
457 * @return PHPExcel_Chart
459 public function setTopLeftCell($cell) {
460 $this->_topLeftCellRef
= $cell;
466 * Set the offset position within the Top Left cell for the chart
468 * @param integer $xOffset
469 * @param integer $yOffset
470 * @return PHPExcel_Chart
472 public function setTopLeftOffset($xOffset=null,$yOffset=null) {
473 if (!is_null($xOffset))
474 $this->setTopLeftXOffset($xOffset);
475 if (!is_null($yOffset))
476 $this->setTopLeftYOffset($yOffset);
482 * Get the offset position within the Top Left cell for the chart
486 public function getTopLeftOffset() {
487 return array( 'X' => $this->_topLeftXOffset
,
488 'Y' => $this->_topLeftYOffset
492 public function setTopLeftXOffset($xOffset) {
493 $this->_topLeftXOffset
= $xOffset;
498 public function getTopLeftXOffset() {
499 return $this->_topLeftXOffset
;
502 public function setTopLeftYOffset($yOffset) {
503 $this->_topLeftYOffset
= $yOffset;
508 public function getTopLeftYOffset() {
509 return $this->_topLeftYOffset
;
513 * Set the Bottom Right position of the chart
515 * @param string $cell
516 * @param integer $xOffset
517 * @param integer $yOffset
518 * @return PHPExcel_Chart
520 public function setBottomRightPosition($cell, $xOffset=null, $yOffset=null) {
521 $this->_bottomRightCellRef
= $cell;
522 if (!is_null($xOffset))
523 $this->setBottomRightXOffset($xOffset);
524 if (!is_null($yOffset))
525 $this->setBottomRightYOffset($yOffset);
531 * Get the bottom right position of the chart
533 * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
535 public function getBottomRightPosition() {
536 return array( 'cell' => $this->_bottomRightCellRef
,
537 'xOffset' => $this->_bottomRightXOffset
,
538 'yOffset' => $this->_bottomRightYOffset
542 public function setBottomRightCell($cell) {
543 $this->_bottomRightCellRef
= $cell;
549 * Get the cell address where the bottom right of the chart is fixed
553 public function getBottomRightCell() {
554 return $this->_bottomRightCellRef
;
558 * Set the offset position within the Bottom Right cell for the chart
560 * @param integer $xOffset
561 * @param integer $yOffset
562 * @return PHPExcel_Chart
564 public function setBottomRightOffset($xOffset=null,$yOffset=null) {
565 if (!is_null($xOffset))
566 $this->setBottomRightXOffset($xOffset);
567 if (!is_null($yOffset))
568 $this->setBottomRightYOffset($yOffset);
574 * Get the offset position within the Bottom Right cell for the chart
578 public function getBottomRightOffset() {
579 return array( 'X' => $this->_bottomRightXOffset
,
580 'Y' => $this->_bottomRightYOffset
584 public function setBottomRightXOffset($xOffset) {
585 $this->_bottomRightXOffset
= $xOffset;
590 public function getBottomRightXOffset() {
591 return $this->_bottomRightXOffset
;
594 public function setBottomRightYOffset($yOffset) {
595 $this->_bottomRightYOffset
= $yOffset;
600 public function getBottomRightYOffset() {
601 return $this->_bottomRightYOffset
;
605 public function refresh() {
606 if ($this->_worksheet
!== NULL) {
607 $this->_plotArea
->refresh($this->_worksheet
);
611 public function render($outputDestination = null) {
612 $libraryName = PHPExcel_Settings
::getChartRendererName();
613 if (is_null($libraryName)) {
616 // Ensure that data series values are up-to-date before we render
619 $libraryPath = PHPExcel_Settings
::getChartRendererPath();
620 $includePath = str_replace('\\','/',get_include_path());
621 $rendererPath = str_replace('\\','/',$libraryPath);
622 if (strpos($rendererPath,$includePath) === false) {
623 set_include_path(get_include_path() . PATH_SEPARATOR
. $libraryPath);
626 $rendererName = 'PHPExcel_Chart_Renderer_'.$libraryName;
627 $renderer = new $rendererName($this);
629 if ($outputDestination == 'php://output') {
630 $outputDestination = null;
632 return $renderer->render($outputDestination);