1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27:
28:
29: 30: 31: 32: 33: 34: 35:
36: class PHPExcel_Chart
37: {
38: 39: 40: 41: 42:
43: private $_name = '';
44:
45: 46: 47: 48: 49:
50: private $_worksheet = null;
51:
52: 53: 54: 55: 56:
57: private $_title = null;
58:
59: 60: 61: 62: 63:
64: private $_legend = null;
65:
66: 67: 68: 69: 70:
71: private $_xAxisLabel = null;
72:
73: 74: 75: 76: 77:
78: private $_yAxisLabel = null;
79:
80: 81: 82: 83: 84:
85: private $_plotArea = null;
86:
87: 88: 89: 90: 91:
92: private $_plotVisibleOnly = true;
93:
94: 95: 96: 97: 98:
99: private $_displayBlanksAs = '0';
100:
101:
102: 103: 104: 105: 106:
107: private $_topLeftCellRef = 'A1';
108:
109:
110: 111: 112: 113: 114:
115: private $_topLeftXOffset = 0;
116:
117:
118: 119: 120: 121: 122:
123: private $_topLeftYOffset = 0;
124:
125:
126: 127: 128: 129: 130:
131: private $_bottomRightCellRef = 'A1';
132:
133:
134: 135: 136: 137: 138:
139: private $_bottomRightXOffset = 10;
140:
141:
142: 143: 144: 145: 146:
147: private $_bottomRightYOffset = 10;
148:
149:
150: 151: 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)
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: }
164:
165: 166: 167: 168: 169:
170: public function getName() {
171: return $this->_name;
172: }
173:
174: 175: 176: 177: 178:
179: public function getWorksheet() {
180: return $this->_worksheet;
181: }
182:
183: 184: 185: 186: 187: 188: 189:
190: public function setWorksheet(PHPExcel_Worksheet $pValue = null) {
191: $this->_worksheet = $pValue;
192:
193: return $this;
194: }
195:
196: 197: 198: 199: 200:
201: public function getTitle() {
202: return $this->_title;
203: }
204:
205: 206: 207: 208: 209: 210:
211: public function setTitle(PHPExcel_Chart_Title $title) {
212: $this->_title = $title;
213:
214: return $this;
215: }
216:
217: 218: 219: 220: 221:
222: public function getLegend() {
223: return $this->_legend;
224: }
225:
226: 227: 228: 229: 230: 231:
232: public function setLegend(PHPExcel_Chart_Legend $legend) {
233: $this->_legend = $legend;
234:
235: return $this;
236: }
237:
238: 239: 240: 241: 242:
243: public function getXAxisLabel() {
244: return $this->_xAxisLabel;
245: }
246:
247: 248: 249: 250: 251: 252:
253: public function setXAxisLabel(PHPExcel_Chart_Title $label) {
254: $this->_xAxisLabel = $label;
255:
256: return $this;
257: }
258:
259: 260: 261: 262: 263:
264: public function getYAxisLabel() {
265: return $this->_yAxisLabel;
266: }
267:
268: 269: 270: 271: 272: 273:
274: public function setYAxisLabel(PHPExcel_Chart_Title $label) {
275: $this->_yAxisLabel = $label;
276:
277: return $this;
278: }
279:
280: 281: 282: 283: 284:
285: public function getPlotArea() {
286: return $this->_plotArea;
287: }
288:
289: 290: 291: 292: 293:
294: public function getPlotVisibleOnly() {
295: return $this->_plotVisibleOnly;
296: }
297:
298: 299: 300: 301: 302: 303:
304: public function setPlotVisibleOnly($plotVisibleOnly = true) {
305: $this->_plotVisibleOnly = $plotVisibleOnly;
306:
307: return $this;
308: }
309:
310: 311: 312: 313: 314:
315: public function getDisplayBlanksAs() {
316: return $this->_displayBlanksAs;
317: }
318:
319: 320: 321: 322: 323: 324:
325: public function setDisplayBlanksAs($displayBlanksAs = '0') {
326: $this->_displayBlanksAs = $displayBlanksAs;
327: }
328:
329:
330: 331: 332: 333: 334: 335: 336: 337:
338: public function setTopLeftPosition($cell, $xOffset=null, $yOffset=null) {
339: $this->_topLeftCellRef = $cell;
340: if (!is_null($xOffset))
341: $this->setTopLeftXOffset($xOffset);
342: if (!is_null($yOffset))
343: $this->setTopLeftYOffset($yOffset);
344:
345: return $this;
346: }
347:
348: 349: 350: 351: 352:
353: public function getTopLeftPosition() {
354: return array( 'cell' => $this->_topLeftCellRef,
355: 'xOffset' => $this->_topLeftXOffset,
356: 'yOffset' => $this->_topLeftYOffset
357: );
358: }
359:
360: 361: 362: 363: 364:
365: public function getTopLeftCell() {
366: return $this->_topLeftCellRef;
367: }
368:
369: 370: 371: 372: 373: 374:
375: public function setTopLeftCell($cell) {
376: $this->_topLeftCellRef = $cell;
377:
378: return $this;
379: }
380:
381: 382: 383: 384: 385: 386: 387:
388: public function setTopLeftOffset($xOffset=null,$yOffset=null) {
389: if (!is_null($xOffset))
390: $this->setTopLeftXOffset($xOffset);
391: if (!is_null($yOffset))
392: $this->setTopLeftYOffset($yOffset);
393:
394: return $this;
395: }
396:
397: 398: 399: 400: 401:
402: public function getTopLeftOffset() {
403: return array( 'X' => $this->_topLeftXOffset,
404: 'Y' => $this->_topLeftYOffset
405: );
406: }
407:
408: public function setTopLeftXOffset($xOffset) {
409: $this->_topLeftXOffset = $xOffset;
410:
411: return $this;
412: }
413:
414: public function getTopLeftXOffset() {
415: return $this->_topLeftXOffset;
416: }
417:
418: public function setTopLeftYOffset($yOffset) {
419: $this->_topLeftYOffset = $yOffset;
420:
421: return $this;
422: }
423:
424: public function getTopLeftYOffset() {
425: return $this->_topLeftYOffset;
426: }
427:
428: 429: 430: 431: 432: 433: 434: 435:
436: public function setBottomRightPosition($cell, $xOffset=null, $yOffset=null) {
437: $this->_bottomRightCellRef = $cell;
438: if (!is_null($xOffset))
439: $this->setBottomRightXOffset($xOffset);
440: if (!is_null($yOffset))
441: $this->setBottomRightYOffset($yOffset);
442:
443: return $this;
444: }
445:
446: 447: 448: 449: 450:
451: public function getBottomRightPosition() {
452: return array( 'cell' => $this->_bottomRightCellRef,
453: 'xOffset' => $this->_bottomRightXOffset,
454: 'yOffset' => $this->_bottomRightYOffset
455: );
456: }
457:
458: public function setBottomRightCell($cell) {
459: $this->_bottomRightCellRef = $cell;
460:
461: return $this;
462: }
463:
464: 465: 466: 467: 468:
469: public function getBottomRightCell() {
470: return $this->_bottomRightCellRef;
471: }
472:
473: 474: 475: 476: 477: 478: 479:
480: public function setBottomRightOffset($xOffset=null,$yOffset=null) {
481: if (!is_null($xOffset))
482: $this->setBottomRightXOffset($xOffset);
483: if (!is_null($yOffset))
484: $this->setBottomRightYOffset($yOffset);
485:
486: return $this;
487: }
488:
489: 490: 491: 492: 493:
494: public function getBottomRightOffset() {
495: return array( 'X' => $this->_bottomRightXOffset,
496: 'Y' => $this->_bottomRightYOffset
497: );
498: }
499:
500: public function setBottomRightXOffset($xOffset) {
501: $this->_bottomRightXOffset = $xOffset;
502:
503: return $this;
504: }
505:
506: public function getBottomRightXOffset() {
507: return $this->_bottomRightXOffset;
508: }
509:
510: public function setBottomRightYOffset($yOffset) {
511: $this->_bottomRightYOffset = $yOffset;
512:
513: return $this;
514: }
515:
516: public function getBottomRightYOffset() {
517: return $this->_bottomRightYOffset;
518: }
519:
520:
521: public function refresh() {
522: if ($this->_worksheet !== NULL) {
523: $this->_plotArea->refresh($this->_worksheet);
524: }
525: }
526:
527: public function render($outputDestination = null) {
528: $libraryName = PHPExcel_Settings::getChartRendererName();
529: if (is_null($libraryName)) {
530: return false;
531: }
532:
533: $this->refresh();
534:
535: $libraryPath = PHPExcel_Settings::getChartRendererPath();
536: $includePath = str_replace('\\','/',get_include_path());
537: $rendererPath = str_replace('\\','/',$libraryPath);
538: if (strpos($rendererPath,$includePath) === false) {
539: set_include_path(get_include_path() . PATH_SEPARATOR . $libraryPath);
540: }
541:
542: $rendererName = 'PHPExcel_Chart_Renderer_'.$libraryName;
543: $renderer = new $rendererName($this);
544:
545: if ($outputDestination == 'php://output') {
546: $outputDestination = null;
547: }
548: return $renderer->render($outputDestination);
549: }
550:
551: }
552: