暂无描述

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Element;
  18. use PhpOffice\PhpWord\Style\Chart as ChartStyle;
  19. /**
  20. * Chart element
  21. *
  22. * @since 0.12.0
  23. */
  24. class Chart extends AbstractElement
  25. {
  26. /**
  27. * Is part of collection
  28. *
  29. * @var bool
  30. */
  31. protected $collectionRelation = true;
  32. /**
  33. * Type
  34. *
  35. * @var string
  36. */
  37. private $type = 'pie';
  38. /**
  39. * Series
  40. *
  41. * @var array
  42. */
  43. private $series = array();
  44. /**
  45. * Chart style
  46. *
  47. * @var \PhpOffice\PhpWord\Style\Chart
  48. */
  49. private $style;
  50. /**
  51. * Create new instance
  52. *
  53. * @param string $type
  54. * @param array $categories
  55. * @param array $values
  56. * @param array $style
  57. */
  58. public function __construct($type, $categories, $values, $style = null)
  59. {
  60. $this->setType($type);
  61. $this->addSeries($categories, $values);
  62. $this->style = $this->setNewStyle(new ChartStyle(), $style, true);
  63. }
  64. /**
  65. * Get type
  66. *
  67. * @return string
  68. */
  69. public function getType()
  70. {
  71. return $this->type;
  72. }
  73. /**
  74. * Set type.
  75. *
  76. * @param string $value
  77. * @return void
  78. */
  79. public function setType($value)
  80. {
  81. $enum = array('pie', 'doughnut', 'line', 'bar', 'column', 'area', 'radar', 'scatter');
  82. $this->type = $this->setEnumVal($value, $enum, 'pie');
  83. }
  84. /**
  85. * Add series
  86. *
  87. * @param array $categories
  88. * @param array $values
  89. * @return void
  90. */
  91. public function addSeries($categories, $values)
  92. {
  93. $this->series[] = array('categories' => $categories, 'values' => $values);
  94. }
  95. /**
  96. * Get series
  97. *
  98. * @return array
  99. */
  100. public function getSeries()
  101. {
  102. return $this->series;
  103. }
  104. /**
  105. * Get chart style
  106. *
  107. * @return \PhpOffice\PhpWord\Style\Chart
  108. */
  109. public function getStyle()
  110. {
  111. return $this->style;
  112. }
  113. }