24194c94087b1f84311a9e602c1032045e59d71a.svn-base 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 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 - 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##
  26. */
  27. /**
  28. * PHPExcel_Chart_DataSeries
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Chart
  32. * @copyright Copyright (c) 2006 - 2014 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 = null;
  72. /**
  73. * Plot Grouping Type
  74. *
  75. * @var boolean
  76. */
  77. private $_plotGrouping = null;
  78. /**
  79. * Plot Direction
  80. *
  81. * @var boolean
  82. */
  83. private $_plotDirection = null;
  84. /**
  85. * Plot Style
  86. *
  87. * @var string
  88. */
  89. private $_plotStyle = null;
  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 = null;
  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. return $this->_plotType;
  152. }
  153. /**
  154. * Set Plot Type
  155. *
  156. * @param string $plotType
  157. * @return PHPExcel_Chart_DataSeries
  158. */
  159. public function setPlotType($plotType = '') {
  160. $this->_plotType = $plotType;
  161. return $this;
  162. }
  163. /**
  164. * Get Plot Grouping Type
  165. *
  166. * @return string
  167. */
  168. public function getPlotGrouping() {
  169. return $this->_plotGrouping;
  170. }
  171. /**
  172. * Set Plot Grouping Type
  173. *
  174. * @param string $groupingType
  175. * @return PHPExcel_Chart_DataSeries
  176. */
  177. public function setPlotGrouping($groupingType = null) {
  178. $this->_plotGrouping = $groupingType;
  179. return $this;
  180. }
  181. /**
  182. * Get Plot Direction
  183. *
  184. * @return string
  185. */
  186. public function getPlotDirection() {
  187. return $this->_plotDirection;
  188. }
  189. /**
  190. * Set Plot Direction
  191. *
  192. * @param string $plotDirection
  193. * @return PHPExcel_Chart_DataSeries
  194. */
  195. public function setPlotDirection($plotDirection = null) {
  196. $this->_plotDirection = $plotDirection;
  197. return $this;
  198. }
  199. /**
  200. * Get Plot Order
  201. *
  202. * @return string
  203. */
  204. public function getPlotOrder() {
  205. return $this->_plotOrder;
  206. }
  207. /**
  208. * Get Plot Labels
  209. *
  210. * @return array of PHPExcel_Chart_DataSeriesValues
  211. */
  212. public function getPlotLabels() {
  213. return $this->_plotLabel;
  214. }
  215. /**
  216. * Get Plot Label by Index
  217. *
  218. * @return PHPExcel_Chart_DataSeriesValues
  219. */
  220. public function getPlotLabelByIndex($index) {
  221. $keys = array_keys($this->_plotLabel);
  222. if (in_array($index,$keys)) {
  223. return $this->_plotLabel[$index];
  224. } elseif(isset($keys[$index])) {
  225. return $this->_plotLabel[$keys[$index]];
  226. }
  227. return false;
  228. }
  229. /**
  230. * Get Plot Categories
  231. *
  232. * @return array of PHPExcel_Chart_DataSeriesValues
  233. */
  234. public function getPlotCategories() {
  235. return $this->_plotCategory;
  236. }
  237. /**
  238. * Get Plot Category by Index
  239. *
  240. * @return PHPExcel_Chart_DataSeriesValues
  241. */
  242. public function getPlotCategoryByIndex($index) {
  243. $keys = array_keys($this->_plotCategory);
  244. if (in_array($index,$keys)) {
  245. return $this->_plotCategory[$index];
  246. } elseif(isset($keys[$index])) {
  247. return $this->_plotCategory[$keys[$index]];
  248. }
  249. return false;
  250. }
  251. /**
  252. * Get Plot Style
  253. *
  254. * @return string
  255. */
  256. public function getPlotStyle() {
  257. return $this->_plotStyle;
  258. }
  259. /**
  260. * Set Plot Style
  261. *
  262. * @param string $plotStyle
  263. * @return PHPExcel_Chart_DataSeries
  264. */
  265. public function setPlotStyle($plotStyle = null) {
  266. $this->_plotStyle = $plotStyle;
  267. return $this;
  268. }
  269. /**
  270. * Get Plot Values
  271. *
  272. * @return array of PHPExcel_Chart_DataSeriesValues
  273. */
  274. public function getPlotValues() {
  275. return $this->_plotValues;
  276. }
  277. /**
  278. * Get Plot Values by Index
  279. *
  280. * @return PHPExcel_Chart_DataSeriesValues
  281. */
  282. public function getPlotValuesByIndex($index) {
  283. $keys = array_keys($this->_plotValues);
  284. if (in_array($index,$keys)) {
  285. return $this->_plotValues[$index];
  286. } elseif(isset($keys[$index])) {
  287. return $this->_plotValues[$keys[$index]];
  288. }
  289. return false;
  290. }
  291. /**
  292. * Get Number of Plot Series
  293. *
  294. * @return integer
  295. */
  296. public function getPlotSeriesCount() {
  297. return count($this->_plotValues);
  298. }
  299. /**
  300. * Get Smooth Line
  301. *
  302. * @return boolean
  303. */
  304. public function getSmoothLine() {
  305. return $this->_smoothLine;
  306. }
  307. /**
  308. * Set Smooth Line
  309. *
  310. * @param boolean $smoothLine
  311. * @return PHPExcel_Chart_DataSeries
  312. */
  313. public function setSmoothLine($smoothLine = TRUE) {
  314. $this->_smoothLine = $smoothLine;
  315. return $this;
  316. }
  317. public function refresh(PHPExcel_Worksheet $worksheet) {
  318. foreach($this->_plotValues as $plotValues) {
  319. if ($plotValues !== NULL)
  320. $plotValues->refresh($worksheet, TRUE);
  321. }
  322. foreach($this->_plotLabel as $plotValues) {
  323. if ($plotValues !== NULL)
  324. $plotValues->refresh($worksheet, TRUE);
  325. }
  326. foreach($this->_plotCategory as $plotValues) {
  327. if ($plotValues !== NULL)
  328. $plotValues->refresh($worksheet, FALSE);
  329. }
  330. }
  331. }