DataSeries.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2015 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 - 2015 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_DataSeries
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Chart
  32. * @copyright Copyright (c) 2006 - 2015 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 TYPE_CANDLECHART = self::TYPE_STOCKCHART; // Synonym
  53. const GROUPING_CLUSTERED = 'clustered';
  54. const GROUPING_STACKED = 'stacked';
  55. const GROUPING_PERCENT_STACKED = 'percentStacked';
  56. const GROUPING_STANDARD = 'standard';
  57. const DIRECTION_BAR = 'bar';
  58. const DIRECTION_HORIZONTAL = self::DIRECTION_BAR;
  59. const DIRECTION_COL = 'col';
  60. const DIRECTION_COLUMN = self::DIRECTION_COL;
  61. const DIRECTION_VERTICAL = self::DIRECTION_COL;
  62. const STYLE_LINEMARKER = 'lineMarker';
  63. const STYLE_SMOOTHMARKER = 'smoothMarker';
  64. const STYLE_MARKER = 'marker';
  65. const STYLE_FILLED = 'filled';
  66. /**
  67. * Series Plot Type
  68. *
  69. * @var string
  70. */
  71. private $plotType;
  72. /**
  73. * Plot Grouping Type
  74. *
  75. * @var boolean
  76. */
  77. private $plotGrouping;
  78. /**
  79. * Plot Direction
  80. *
  81. * @var boolean
  82. */
  83. private $plotDirection;
  84. /**
  85. * Plot Style
  86. *
  87. * @var string
  88. */
  89. private $plotStyle;
  90. /**
  91. * Order of plots in Series
  92. *
  93. * @var array of integer
  94. */
  95. private $plotOrder = array();
  96. /**
  97. * Plot Label
  98. *
  99. * @var array of PHPExcel_Chart_DataSeriesValues
  100. */
  101. private $plotLabel = array();
  102. /**
  103. * Plot Category
  104. *
  105. * @var array of PHPExcel_Chart_DataSeriesValues
  106. */
  107. private $plotCategory = array();
  108. /**
  109. * Smooth Line
  110. *
  111. * @var string
  112. */
  113. private $smoothLine;
  114. /**
  115. * Plot Values
  116. *
  117. * @var array of PHPExcel_Chart_DataSeriesValues
  118. */
  119. private $plotValues = array();
  120. /**
  121. * Create a new PHPExcel_Chart_DataSeries
  122. */
  123. public function __construct($plotType = null, $plotGrouping = null, $plotOrder = array(), $plotLabel = array(), $plotCategory = array(), $plotValues = array(), $plotDirection = null, $smoothLine = null, $plotStyle = null)
  124. {
  125. $this->plotType = $plotType;
  126. $this->plotGrouping = $plotGrouping;
  127. $this->plotOrder = $plotOrder;
  128. $keys = array_keys($plotValues);
  129. $this->plotValues = $plotValues;
  130. if ((count($plotLabel) == 0) || (is_null($plotLabel[$keys[0]]))) {
  131. $plotLabel[$keys[0]] = new PHPExcel_Chart_DataSeriesValues();
  132. }
  133. $this->plotLabel = $plotLabel;
  134. if ((count($plotCategory) == 0) || (is_null($plotCategory[$keys[0]]))) {
  135. $plotCategory[$keys[0]] = new PHPExcel_Chart_DataSeriesValues();
  136. }
  137. $this->plotCategory = $plotCategory;
  138. $this->smoothLine = $smoothLine;
  139. $this->plotStyle = $plotStyle;
  140. if (is_null($plotDirection)) {
  141. $plotDirection = self::DIRECTION_COL;
  142. }
  143. $this->plotDirection = $plotDirection;
  144. }
  145. /**
  146. * Get Plot Type
  147. *
  148. * @return string
  149. */
  150. public function getPlotType()
  151. {
  152. return $this->plotType;
  153. }
  154. /**
  155. * Set Plot Type
  156. *
  157. * @param string $plotType
  158. * @return PHPExcel_Chart_DataSeries
  159. */
  160. public function setPlotType($plotType = '')
  161. {
  162. $this->plotType = $plotType;
  163. return $this;
  164. }
  165. /**
  166. * Get Plot Grouping Type
  167. *
  168. * @return string
  169. */
  170. public function getPlotGrouping()
  171. {
  172. return $this->plotGrouping;
  173. }
  174. /**
  175. * Set Plot Grouping Type
  176. *
  177. * @param string $groupingType
  178. * @return PHPExcel_Chart_DataSeries
  179. */
  180. public function setPlotGrouping($groupingType = null)
  181. {
  182. $this->plotGrouping = $groupingType;
  183. return $this;
  184. }
  185. /**
  186. * Get Plot Direction
  187. *
  188. * @return string
  189. */
  190. public function getPlotDirection()
  191. {
  192. return $this->plotDirection;
  193. }
  194. /**
  195. * Set Plot Direction
  196. *
  197. * @param string $plotDirection
  198. * @return PHPExcel_Chart_DataSeries
  199. */
  200. public function setPlotDirection($plotDirection = null)
  201. {
  202. $this->plotDirection = $plotDirection;
  203. return $this;
  204. }
  205. /**
  206. * Get Plot Order
  207. *
  208. * @return string
  209. */
  210. public function getPlotOrder()
  211. {
  212. return $this->plotOrder;
  213. }
  214. /**
  215. * Get Plot Labels
  216. *
  217. * @return array of PHPExcel_Chart_DataSeriesValues
  218. */
  219. public function getPlotLabels()
  220. {
  221. return $this->plotLabel;
  222. }
  223. /**
  224. * Get Plot Label by Index
  225. *
  226. * @return PHPExcel_Chart_DataSeriesValues
  227. */
  228. public function getPlotLabelByIndex($index)
  229. {
  230. $keys = array_keys($this->plotLabel);
  231. if (in_array($index, $keys)) {
  232. return $this->plotLabel[$index];
  233. } elseif (isset($keys[$index])) {
  234. return $this->plotLabel[$keys[$index]];
  235. }
  236. return false;
  237. }
  238. /**
  239. * Get Plot Categories
  240. *
  241. * @return array of PHPExcel_Chart_DataSeriesValues
  242. */
  243. public function getPlotCategories()
  244. {
  245. return $this->plotCategory;
  246. }
  247. /**
  248. * Get Plot Category by Index
  249. *
  250. * @return PHPExcel_Chart_DataSeriesValues
  251. */
  252. public function getPlotCategoryByIndex($index)
  253. {
  254. $keys = array_keys($this->plotCategory);
  255. if (in_array($index, $keys)) {
  256. return $this->plotCategory[$index];
  257. } elseif (isset($keys[$index])) {
  258. return $this->plotCategory[$keys[$index]];
  259. }
  260. return false;
  261. }
  262. /**
  263. * Get Plot Style
  264. *
  265. * @return string
  266. */
  267. public function getPlotStyle()
  268. {
  269. return $this->plotStyle;
  270. }
  271. /**
  272. * Set Plot Style
  273. *
  274. * @param string $plotStyle
  275. * @return PHPExcel_Chart_DataSeries
  276. */
  277. public function setPlotStyle($plotStyle = null)
  278. {
  279. $this->plotStyle = $plotStyle;
  280. return $this;
  281. }
  282. /**
  283. * Get Plot Values
  284. *
  285. * @return array of PHPExcel_Chart_DataSeriesValues
  286. */
  287. public function getPlotValues()
  288. {
  289. return $this->plotValues;
  290. }
  291. /**
  292. * Get Plot Values by Index
  293. *
  294. * @return PHPExcel_Chart_DataSeriesValues
  295. */
  296. public function getPlotValuesByIndex($index)
  297. {
  298. $keys = array_keys($this->plotValues);
  299. if (in_array($index, $keys)) {
  300. return $this->plotValues[$index];
  301. } elseif (isset($keys[$index])) {
  302. return $this->plotValues[$keys[$index]];
  303. }
  304. return false;
  305. }
  306. /**
  307. * Get Number of Plot Series
  308. *
  309. * @return integer
  310. */
  311. public function getPlotSeriesCount()
  312. {
  313. return count($this->plotValues);
  314. }
  315. /**
  316. * Get Smooth Line
  317. *
  318. * @return boolean
  319. */
  320. public function getSmoothLine()
  321. {
  322. return $this->smoothLine;
  323. }
  324. /**
  325. * Set Smooth Line
  326. *
  327. * @param boolean $smoothLine
  328. * @return PHPExcel_Chart_DataSeries
  329. */
  330. public function setSmoothLine($smoothLine = true)
  331. {
  332. $this->smoothLine = $smoothLine;
  333. return $this;
  334. }
  335. public function refresh(PHPExcel_Worksheet $worksheet)
  336. {
  337. foreach ($this->plotValues as $plotValues) {
  338. if ($plotValues !== null) {
  339. $plotValues->refresh($worksheet, true);
  340. }
  341. }
  342. foreach ($this->plotLabel as $plotValues) {
  343. if ($plotValues !== null) {
  344. $plotValues->refresh($worksheet, true);
  345. }
  346. }
  347. foreach ($this->plotCategory as $plotValues) {
  348. if ($plotValues !== null) {
  349. $plotValues->refresh($worksheet, false);
  350. }
  351. }
  352. }
  353. }