DataSeries.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2013 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 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.9, 2013-06-02
  26. */
  27. /**
  28. * PHPExcel_Chart_DataSeries
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Chart
  32. * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Chart_DataSeries
  35. {
  36. const TYPE_BARCHART = 'barChart';
  37. const TYPE_BARCHART_3D = 'bar3DChart';
  38. const TYPE_LINECHART = 'lineChart';
  39. const TYPE_LINECHART_3D = 'line3DChart';
  40. const TYPE_AREACHART = 'areaChart';
  41. const TYPE_AREACHART_3D = 'area3DChart';
  42. const TYPE_PIECHART = 'pieChart';
  43. const TYPE_PIECHART_3D = 'pie3DChart';
  44. const TYPE_DOUGHTNUTCHART = 'doughnutChart';
  45. const TYPE_DONUTCHART = self::TYPE_DOUGHTNUTCHART; // Synonym
  46. const TYPE_SCATTERCHART = 'scatterChart';
  47. const TYPE_SURFACECHART = 'surfaceChart';
  48. const TYPE_SURFACECHART_3D = 'surface3DChart';
  49. const TYPE_RADARCHART = 'radarChart';
  50. const TYPE_BUBBLECHART = 'bubbleChart';
  51. const TYPE_STOCKCHART = 'stockChart';
  52. const GROUPING_CLUSTERED = 'clustered';
  53. const GROUPING_STACKED = 'stacked';
  54. const GROUPING_PERCENT_STACKED = 'percentStacked';
  55. const GROUPING_STANDARD = 'standard';
  56. const DIRECTION_BAR = 'bar';
  57. const DIRECTION_HORIZONTAL = self::DIRECTION_BAR;
  58. const DIRECTION_COL = 'col';
  59. const DIRECTION_COLUMN = self::DIRECTION_COL;
  60. const DIRECTION_VERTICAL = self::DIRECTION_COL;
  61. const STYLE_LINEMARKER = 'lineMarker';
  62. const STYLE_SMOOTHMARKER = 'smoothMarker';
  63. const STYLE_MARKER = 'marker';
  64. const STYLE_FILLED = 'filled';
  65. /**
  66. * Series Plot Type
  67. *
  68. * @var string
  69. */
  70. private $_plotType = null;
  71. /**
  72. * Plot Grouping Type
  73. *
  74. * @var boolean
  75. */
  76. private $_plotGrouping = null;
  77. /**
  78. * Plot Direction
  79. *
  80. * @var boolean
  81. */
  82. private $_plotDirection = null;
  83. /**
  84. * Plot Style
  85. *
  86. * @var string
  87. */
  88. private $_plotStyle = null;
  89. /**
  90. * Order of plots in Series
  91. *
  92. * @var array of integer
  93. */
  94. private $_plotOrder = array();
  95. /**
  96. * Plot Label
  97. *
  98. * @var array of PHPExcel_Chart_DataSeriesValues
  99. */
  100. private $_plotLabel = array();
  101. /**
  102. * Plot Category
  103. *
  104. * @var array of PHPExcel_Chart_DataSeriesValues
  105. */
  106. private $_plotCategory = array();
  107. /**
  108. * Smooth Line
  109. *
  110. * @var string
  111. */
  112. private $_smoothLine = null;
  113. /**
  114. * Plot Values
  115. *
  116. * @var array of PHPExcel_Chart_DataSeriesValues
  117. */
  118. private $_plotValues = array();
  119. /**
  120. * Create a new PHPExcel_Chart_DataSeries
  121. */
  122. public function __construct($plotType = null, $plotGrouping = null, $plotOrder = array(), $plotLabel = array(), $plotCategory = array(), $plotValues = array(), $smoothLine = null, $plotStyle = null)
  123. {
  124. $this->_plotType = $plotType;
  125. $this->_plotGrouping = $plotGrouping;
  126. $this->_plotOrder = $plotOrder;
  127. $keys = array_keys($plotValues);
  128. $this->_plotValues = $plotValues;
  129. if ((count($plotLabel) == 0) || (is_null($plotLabel[$keys[0]]))) {
  130. $plotLabel[$keys[0]] = new PHPExcel_Chart_DataSeriesValues();
  131. }
  132. $this->_plotLabel = $plotLabel;
  133. if ((count($plotCategory) == 0) || (is_null($plotCategory[$keys[0]]))) {
  134. $plotCategory[$keys[0]] = new PHPExcel_Chart_DataSeriesValues();
  135. }
  136. $this->_plotCategory = $plotCategory;
  137. $this->_smoothLine = $smoothLine;
  138. $this->_plotStyle = $plotStyle;
  139. }
  140. /**
  141. * Get Plot Type
  142. *
  143. * @return string
  144. */
  145. public function getPlotType() {
  146. return $this->_plotType;
  147. }
  148. /**
  149. * Set Plot Type
  150. *
  151. * @param string $plotType
  152. */
  153. public function setPlotType($plotType = '') {
  154. $this->_plotType = $plotType;
  155. }
  156. /**
  157. * Get Plot Grouping Type
  158. *
  159. * @return string
  160. */
  161. public function getPlotGrouping() {
  162. return $this->_plotGrouping;
  163. }
  164. /**
  165. * Set Plot Grouping Type
  166. *
  167. * @param string $groupingType
  168. */
  169. public function setPlotGrouping($groupingType = null) {
  170. $this->_plotGrouping = $groupingType;
  171. }
  172. /**
  173. * Get Plot Direction
  174. *
  175. * @return string
  176. */
  177. public function getPlotDirection() {
  178. return $this->_plotDirection;
  179. }
  180. /**
  181. * Set Plot Direction
  182. *
  183. * @param string $plotDirection
  184. */
  185. public function setPlotDirection($plotDirection = null) {
  186. $this->_plotDirection = $plotDirection;
  187. }
  188. /**
  189. * Get Plot Order
  190. *
  191. * @return string
  192. */
  193. public function getPlotOrder() {
  194. return $this->_plotOrder;
  195. }
  196. /**
  197. * Get Plot Labels
  198. *
  199. * @return array of PHPExcel_Chart_DataSeriesValues
  200. */
  201. public function getPlotLabels() {
  202. return $this->_plotLabel;
  203. }
  204. /**
  205. * Get Plot Label by Index
  206. *
  207. * @return PHPExcel_Chart_DataSeriesValues
  208. */
  209. public function getPlotLabelByIndex($index) {
  210. $keys = array_keys($this->_plotLabel);
  211. if (in_array($index,$keys)) {
  212. return $this->_plotLabel[$index];
  213. } elseif(isset($keys[$index])) {
  214. return $this->_plotLabel[$keys[$index]];
  215. }
  216. return false;
  217. }
  218. /**
  219. * Get Plot Categories
  220. *
  221. * @return array of PHPExcel_Chart_DataSeriesValues
  222. */
  223. public function getPlotCategories() {
  224. return $this->_plotCategory;
  225. }
  226. /**
  227. * Get Plot Category by Index
  228. *
  229. * @return PHPExcel_Chart_DataSeriesValues
  230. */
  231. public function getPlotCategoryByIndex($index) {
  232. $keys = array_keys($this->_plotCategory);
  233. if (in_array($index,$keys)) {
  234. return $this->_plotCategory[$index];
  235. } elseif(isset($keys[$index])) {
  236. return $this->_plotCategory[$keys[$index]];
  237. }
  238. return false;
  239. }
  240. /**
  241. * Get Plot Style
  242. *
  243. * @return string
  244. */
  245. public function getPlotStyle() {
  246. return $this->_plotStyle;
  247. }
  248. /**
  249. * Set Plot Style
  250. *
  251. * @param string $plotStyle
  252. */
  253. public function setPlotStyle($plotStyle = null) {
  254. $this->_plotStyle = $plotStyle;
  255. }
  256. /**
  257. * Get Plot Values
  258. *
  259. * @return array of PHPExcel_Chart_DataSeriesValues
  260. */
  261. public function getPlotValues() {
  262. return $this->_plotValues;
  263. }
  264. /**
  265. * Get Plot Values by Index
  266. *
  267. * @return PHPExcel_Chart_DataSeriesValues
  268. */
  269. public function getPlotValuesByIndex($index) {
  270. $keys = array_keys($this->_plotValues);
  271. if (in_array($index,$keys)) {
  272. return $this->_plotValues[$index];
  273. } elseif(isset($keys[$index])) {
  274. return $this->_plotValues[$keys[$index]];
  275. }
  276. return false;
  277. }
  278. /**
  279. * Get Number of Plot Series
  280. *
  281. * @return integer
  282. */
  283. public function getPlotSeriesCount() {
  284. return count($this->_plotValues);
  285. }
  286. /**
  287. * Get Smooth Line
  288. *
  289. * @return boolean
  290. */
  291. public function getSmoothLine() {
  292. return $this->_smoothLine;
  293. }
  294. /**
  295. * Set Smooth Line
  296. *
  297. * @param boolean $smoothLine
  298. */
  299. public function setSmoothLine($smoothLine = TRUE) {
  300. $this->_smoothLine = $smoothLine;
  301. }
  302. public function refresh(PHPExcel_Worksheet $worksheet) {
  303. foreach($this->_plotValues as $plotValues) {
  304. if ($plotValues !== NULL)
  305. $plotValues->refresh($worksheet, TRUE);
  306. }
  307. foreach($this->_plotLabel as $plotValues) {
  308. if ($plotValues !== NULL)
  309. $plotValues->refresh($worksheet, TRUE);
  310. }
  311. foreach($this->_plotCategory as $plotValues) {
  312. if ($plotValues !== NULL)
  313. $plotValues->refresh($worksheet, FALSE);
  314. }
  315. }
  316. }