1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | * Author Change Date
|
---|
28 | *******************************************************************************
|
---|
29 | * Jan Källman Added 2009-10-01
|
---|
30 | * Jan Källman License changed GPL-->LGPL 2011-12-16
|
---|
31 | *******************************************************************************/
|
---|
32 | using System;
|
---|
33 | using System.Collections.Generic;
|
---|
34 | using System.Text;
|
---|
35 | using System.Xml;
|
---|
36 | using OfficeOpenXml.Table.PivotTable;
|
---|
37 |
|
---|
38 | namespace OfficeOpenXml.Drawing.Chart
|
---|
39 | {
|
---|
40 | /// <summary>
|
---|
41 | /// Bar chart
|
---|
42 | /// </summary>
|
---|
43 | public sealed class ExcelBarChart : ExcelChart
|
---|
44 | {
|
---|
45 | #region "Constructors"
|
---|
46 | //internal ExcelBarChart(ExcelDrawings drawings, XmlNode node) :
|
---|
47 | // base(drawings, node/*, 1*/)
|
---|
48 | //{
|
---|
49 | // SetChartNodeText("");
|
---|
50 | //}
|
---|
51 | //internal ExcelBarChart(ExcelDrawings drawings, XmlNode node, eChartType type) :
|
---|
52 | // base(drawings, node, type)
|
---|
53 | //{
|
---|
54 | // SetChartNodeText("");
|
---|
55 |
|
---|
56 | // SetTypeProperties(drawings, type);
|
---|
57 | //}
|
---|
58 | internal ExcelBarChart(ExcelDrawings drawings, XmlNode node, eChartType type, ExcelChart topChart, ExcelPivotTable PivotTableSource) :
|
---|
59 | base(drawings, node, type, topChart, PivotTableSource)
|
---|
60 | {
|
---|
61 | SetChartNodeText("");
|
---|
62 |
|
---|
63 | SetTypeProperties(drawings, type);
|
---|
64 | }
|
---|
65 |
|
---|
66 | internal ExcelBarChart(ExcelDrawings drawings, XmlNode node, Uri uriChart, Packaging.ZipPackagePart part, XmlDocument chartXml, XmlNode chartNode) :
|
---|
67 | base(drawings, node, uriChart, part, chartXml, chartNode)
|
---|
68 | {
|
---|
69 | SetChartNodeText(chartNode.Name);
|
---|
70 | }
|
---|
71 |
|
---|
72 | internal ExcelBarChart(ExcelChart topChart, XmlNode chartNode) :
|
---|
73 | base(topChart, chartNode)
|
---|
74 | {
|
---|
75 | SetChartNodeText(chartNode.Name);
|
---|
76 | }
|
---|
77 | #endregion
|
---|
78 | #region "Private functions"
|
---|
79 | //string _chartTopPath="c:chartSpace/c:chart/c:plotArea/{0}";
|
---|
80 | private void SetChartNodeText(string chartNodeText)
|
---|
81 | {
|
---|
82 | if(string.IsNullOrEmpty(chartNodeText))
|
---|
83 | {
|
---|
84 | chartNodeText = GetChartNodeText();
|
---|
85 | }
|
---|
86 | //_chartTopPath = string.Format(_chartTopPath, chartNodeText);
|
---|
87 | //_directionPath = string.Format(_directionPath, _chartTopPath);
|
---|
88 | //_shapePath = string.Format(_shapePath, _chartTopPath);
|
---|
89 | }
|
---|
90 | private void SetTypeProperties(ExcelDrawings drawings, eChartType type)
|
---|
91 | {
|
---|
92 | /******* Bar direction *******/
|
---|
93 | if (type == eChartType.BarClustered ||
|
---|
94 | type == eChartType.BarStacked ||
|
---|
95 | type == eChartType.BarStacked100 ||
|
---|
96 | type == eChartType.BarClustered3D ||
|
---|
97 | type == eChartType.BarStacked3D ||
|
---|
98 | type == eChartType.BarStacked1003D ||
|
---|
99 | type == eChartType.ConeBarClustered ||
|
---|
100 | type == eChartType.ConeBarStacked ||
|
---|
101 | type == eChartType.ConeBarStacked100 ||
|
---|
102 | type == eChartType.CylinderBarClustered ||
|
---|
103 | type == eChartType.CylinderBarStacked ||
|
---|
104 | type == eChartType.CylinderBarStacked100 ||
|
---|
105 | type == eChartType.PyramidBarClustered ||
|
---|
106 | type == eChartType.PyramidBarStacked ||
|
---|
107 | type == eChartType.PyramidBarStacked100)
|
---|
108 | {
|
---|
109 | Direction = eDirection.Bar;
|
---|
110 | }
|
---|
111 | else if (
|
---|
112 | type == eChartType.ColumnClustered ||
|
---|
113 | type == eChartType.ColumnStacked ||
|
---|
114 | type == eChartType.ColumnStacked100 ||
|
---|
115 | type == eChartType.Column3D ||
|
---|
116 | type == eChartType.ColumnClustered3D ||
|
---|
117 | type == eChartType.ColumnStacked3D ||
|
---|
118 | type == eChartType.ColumnStacked1003D ||
|
---|
119 | type == eChartType.ConeCol ||
|
---|
120 | type == eChartType.ConeColClustered ||
|
---|
121 | type == eChartType.ConeColStacked ||
|
---|
122 | type == eChartType.ConeColStacked100 ||
|
---|
123 | type == eChartType.CylinderCol ||
|
---|
124 | type == eChartType.CylinderColClustered ||
|
---|
125 | type == eChartType.CylinderColStacked ||
|
---|
126 | type == eChartType.CylinderColStacked100 ||
|
---|
127 | type == eChartType.PyramidCol ||
|
---|
128 | type == eChartType.PyramidColClustered ||
|
---|
129 | type == eChartType.PyramidColStacked ||
|
---|
130 | type == eChartType.PyramidColStacked100)
|
---|
131 | {
|
---|
132 | Direction = eDirection.Column;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /****** Shape ******/
|
---|
136 | if (/*type == eChartType.ColumnClustered ||
|
---|
137 | type == eChartType.ColumnStacked ||
|
---|
138 | type == eChartType.ColumnStacked100 ||*/
|
---|
139 | type == eChartType.Column3D ||
|
---|
140 | type == eChartType.ColumnClustered3D ||
|
---|
141 | type == eChartType.ColumnStacked3D ||
|
---|
142 | type == eChartType.ColumnStacked1003D ||
|
---|
143 | /*type == eChartType.BarClustered ||
|
---|
144 | type == eChartType.BarStacked ||
|
---|
145 | type == eChartType.BarStacked100 ||*/
|
---|
146 | type == eChartType.BarClustered3D ||
|
---|
147 | type == eChartType.BarStacked3D ||
|
---|
148 | type == eChartType.BarStacked1003D)
|
---|
149 | {
|
---|
150 | Shape = eShape.Box;
|
---|
151 | }
|
---|
152 | else if (
|
---|
153 | type == eChartType.CylinderBarClustered ||
|
---|
154 | type == eChartType.CylinderBarStacked ||
|
---|
155 | type == eChartType.CylinderBarStacked100 ||
|
---|
156 | type == eChartType.CylinderCol ||
|
---|
157 | type == eChartType.CylinderColClustered ||
|
---|
158 | type == eChartType.CylinderColStacked ||
|
---|
159 | type == eChartType.CylinderColStacked100)
|
---|
160 | {
|
---|
161 | Shape = eShape.Cylinder;
|
---|
162 | }
|
---|
163 | else if (
|
---|
164 | type == eChartType.ConeBarClustered ||
|
---|
165 | type == eChartType.ConeBarStacked ||
|
---|
166 | type == eChartType.ConeBarStacked100 ||
|
---|
167 | type == eChartType.ConeCol ||
|
---|
168 | type == eChartType.ConeColClustered ||
|
---|
169 | type == eChartType.ConeColStacked ||
|
---|
170 | type == eChartType.ConeColStacked100)
|
---|
171 | {
|
---|
172 | Shape = eShape.Cone;
|
---|
173 | }
|
---|
174 | else if (
|
---|
175 | type == eChartType.PyramidBarClustered ||
|
---|
176 | type == eChartType.PyramidBarStacked ||
|
---|
177 | type == eChartType.PyramidBarStacked100 ||
|
---|
178 | type == eChartType.PyramidCol ||
|
---|
179 | type == eChartType.PyramidColClustered ||
|
---|
180 | type == eChartType.PyramidColStacked ||
|
---|
181 | type == eChartType.PyramidColStacked100)
|
---|
182 | {
|
---|
183 | Shape = eShape.Pyramid;
|
---|
184 | }
|
---|
185 | }
|
---|
186 | #endregion
|
---|
187 | #region "Properties"
|
---|
188 | string _directionPath = "c:barDir/@val";
|
---|
189 | /// <summary>
|
---|
190 | /// Direction, Bar or columns
|
---|
191 | /// </summary>
|
---|
192 | public eDirection Direction
|
---|
193 | {
|
---|
194 | get
|
---|
195 | {
|
---|
196 | return GetDirectionEnum(_chartXmlHelper.GetXmlNodeString(_directionPath));
|
---|
197 | }
|
---|
198 | internal set
|
---|
199 | {
|
---|
200 | _chartXmlHelper.SetXmlNodeString(_directionPath, GetDirectionText(value));
|
---|
201 | }
|
---|
202 | }
|
---|
203 | string _shapePath = "c:shape/@val";
|
---|
204 | /// <summary>
|
---|
205 | /// The shape of the bar/columns
|
---|
206 | /// </summary>
|
---|
207 | public eShape Shape
|
---|
208 | {
|
---|
209 | get
|
---|
210 | {
|
---|
211 | return GetShapeEnum(_chartXmlHelper.GetXmlNodeString(_shapePath));
|
---|
212 | }
|
---|
213 | internal set
|
---|
214 | {
|
---|
215 | _chartXmlHelper.SetXmlNodeString(_shapePath, GetShapeText(value));
|
---|
216 | }
|
---|
217 | }
|
---|
218 | ExcelChartDataLabel _DataLabel = null;
|
---|
219 | /// <summary>
|
---|
220 | /// Access to datalabel properties
|
---|
221 | /// </summary>
|
---|
222 | public ExcelChartDataLabel DataLabel
|
---|
223 | {
|
---|
224 | get
|
---|
225 | {
|
---|
226 | if (_DataLabel == null)
|
---|
227 | {
|
---|
228 | _DataLabel = new ExcelChartDataLabel(NameSpaceManager, ChartNode);
|
---|
229 | }
|
---|
230 | return _DataLabel;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | #endregion
|
---|
234 | #region "Direction Enum Traslation"
|
---|
235 | private string GetDirectionText(eDirection direction)
|
---|
236 | {
|
---|
237 | switch (direction)
|
---|
238 | {
|
---|
239 | case eDirection.Bar:
|
---|
240 | return "bar";
|
---|
241 | default:
|
---|
242 | return "col";
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | private eDirection GetDirectionEnum(string direction)
|
---|
247 | {
|
---|
248 | switch (direction)
|
---|
249 | {
|
---|
250 | case "bar":
|
---|
251 | return eDirection.Bar;
|
---|
252 | default:
|
---|
253 | return eDirection.Column;
|
---|
254 | }
|
---|
255 | }
|
---|
256 | #endregion
|
---|
257 | #region "Shape Enum Translation"
|
---|
258 | private string GetShapeText(eShape Shape)
|
---|
259 | {
|
---|
260 | switch (Shape)
|
---|
261 | {
|
---|
262 | case eShape.Box:
|
---|
263 | return "box";
|
---|
264 | case eShape.Cone:
|
---|
265 | return "cone";
|
---|
266 | case eShape.ConeToMax:
|
---|
267 | return "coneToMax";
|
---|
268 | case eShape.Cylinder:
|
---|
269 | return "cylinder";
|
---|
270 | case eShape.Pyramid:
|
---|
271 | return "pyramid";
|
---|
272 | case eShape.PyramidToMax:
|
---|
273 | return "pyramidToMax";
|
---|
274 | default:
|
---|
275 | return "box";
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | private eShape GetShapeEnum(string text)
|
---|
280 | {
|
---|
281 | switch (text)
|
---|
282 | {
|
---|
283 | case "box":
|
---|
284 | return eShape.Box;
|
---|
285 | case "cone":
|
---|
286 | return eShape.Cone;
|
---|
287 | case "coneToMax":
|
---|
288 | return eShape.ConeToMax;
|
---|
289 | case "cylinder":
|
---|
290 | return eShape.Cylinder;
|
---|
291 | case "pyramid":
|
---|
292 | return eShape.Pyramid;
|
---|
293 | case "pyramidToMax":
|
---|
294 | return eShape.PyramidToMax;
|
---|
295 | default:
|
---|
296 | return eShape.Box;
|
---|
297 | }
|
---|
298 | }
|
---|
299 | #endregion
|
---|
300 | internal override eChartType GetChartType(string name)
|
---|
301 | {
|
---|
302 | if (name == "barChart")
|
---|
303 | {
|
---|
304 | if (this.Direction == eDirection.Bar)
|
---|
305 | {
|
---|
306 | if (Grouping == eGrouping.Stacked)
|
---|
307 | {
|
---|
308 | return eChartType.BarStacked;
|
---|
309 | }
|
---|
310 | else if (Grouping == eGrouping.PercentStacked)
|
---|
311 | {
|
---|
312 | return eChartType.BarStacked100;
|
---|
313 | }
|
---|
314 | else
|
---|
315 | {
|
---|
316 | return eChartType.BarClustered;
|
---|
317 | }
|
---|
318 | }
|
---|
319 | else
|
---|
320 | {
|
---|
321 | if (Grouping == eGrouping.Stacked)
|
---|
322 | {
|
---|
323 | return eChartType.ColumnStacked;
|
---|
324 | }
|
---|
325 | else if (Grouping == eGrouping.PercentStacked)
|
---|
326 | {
|
---|
327 | return eChartType.ColumnStacked100;
|
---|
328 | }
|
---|
329 | else
|
---|
330 | {
|
---|
331 | return eChartType.ColumnClustered;
|
---|
332 | }
|
---|
333 | }
|
---|
334 | }
|
---|
335 | if (name == "bar3DChart")
|
---|
336 | {
|
---|
337 | #region "Bar Shape"
|
---|
338 | if (this.Shape==eShape.Box)
|
---|
339 | {
|
---|
340 | if (this.Direction == eDirection.Bar)
|
---|
341 | {
|
---|
342 | if (Grouping == eGrouping.Stacked)
|
---|
343 | {
|
---|
344 | return eChartType.BarStacked3D;
|
---|
345 | }
|
---|
346 | else if (Grouping == eGrouping.PercentStacked)
|
---|
347 | {
|
---|
348 | return eChartType.BarStacked1003D;
|
---|
349 | }
|
---|
350 | else
|
---|
351 | {
|
---|
352 | return eChartType.BarClustered3D;
|
---|
353 | }
|
---|
354 | }
|
---|
355 | else
|
---|
356 | {
|
---|
357 | if (Grouping == eGrouping.Stacked)
|
---|
358 | {
|
---|
359 | return eChartType.ColumnStacked3D;
|
---|
360 | }
|
---|
361 | else if (Grouping == eGrouping.PercentStacked)
|
---|
362 | {
|
---|
363 | return eChartType.ColumnStacked1003D;
|
---|
364 | }
|
---|
365 | else
|
---|
366 | {
|
---|
367 | return eChartType.ColumnClustered3D;
|
---|
368 | }
|
---|
369 | }
|
---|
370 | }
|
---|
371 | #endregion
|
---|
372 | #region "Cone Shape"
|
---|
373 | if (this.Shape == eShape.Cone || this.Shape == eShape.ConeToMax)
|
---|
374 | {
|
---|
375 | if (this.Direction == eDirection.Bar)
|
---|
376 | {
|
---|
377 | if (Grouping == eGrouping.Stacked)
|
---|
378 | {
|
---|
379 | return eChartType.ConeBarStacked;
|
---|
380 | }
|
---|
381 | else if (Grouping == eGrouping.PercentStacked)
|
---|
382 | {
|
---|
383 | return eChartType.ConeBarStacked100;
|
---|
384 | }
|
---|
385 | else if (Grouping == eGrouping.Clustered)
|
---|
386 | {
|
---|
387 | return eChartType.ConeBarClustered;
|
---|
388 | }
|
---|
389 | }
|
---|
390 | else
|
---|
391 | {
|
---|
392 | if (Grouping == eGrouping.Stacked)
|
---|
393 | {
|
---|
394 | return eChartType.ConeColStacked;
|
---|
395 | }
|
---|
396 | else if (Grouping == eGrouping.PercentStacked)
|
---|
397 | {
|
---|
398 | return eChartType.ConeColStacked100;
|
---|
399 | }
|
---|
400 | else if (Grouping == eGrouping.Clustered)
|
---|
401 | {
|
---|
402 | return eChartType.ConeColClustered;
|
---|
403 | }
|
---|
404 | else
|
---|
405 | {
|
---|
406 | return eChartType.ConeCol;
|
---|
407 | }
|
---|
408 | }
|
---|
409 | }
|
---|
410 | #endregion
|
---|
411 | #region "Cylinder Shape"
|
---|
412 | if (this.Shape == eShape.Cylinder)
|
---|
413 | {
|
---|
414 | if (this.Direction == eDirection.Bar)
|
---|
415 | {
|
---|
416 | if (Grouping == eGrouping.Stacked)
|
---|
417 | {
|
---|
418 | return eChartType.CylinderBarStacked;
|
---|
419 | }
|
---|
420 | else if (Grouping == eGrouping.PercentStacked)
|
---|
421 | {
|
---|
422 | return eChartType.CylinderBarStacked100;
|
---|
423 | }
|
---|
424 | else if (Grouping == eGrouping.Clustered)
|
---|
425 | {
|
---|
426 | return eChartType.CylinderBarClustered;
|
---|
427 | }
|
---|
428 | }
|
---|
429 | else
|
---|
430 | {
|
---|
431 | if (Grouping == eGrouping.Stacked)
|
---|
432 | {
|
---|
433 | return eChartType.CylinderColStacked;
|
---|
434 | }
|
---|
435 | else if (Grouping == eGrouping.PercentStacked)
|
---|
436 | {
|
---|
437 | return eChartType.CylinderColStacked100;
|
---|
438 | }
|
---|
439 | else if (Grouping == eGrouping.Clustered)
|
---|
440 | {
|
---|
441 | return eChartType.CylinderColClustered;
|
---|
442 | }
|
---|
443 | else
|
---|
444 | {
|
---|
445 | return eChartType.CylinderCol;
|
---|
446 | }
|
---|
447 | }
|
---|
448 | }
|
---|
449 | #endregion
|
---|
450 | #region "Pyramide Shape"
|
---|
451 | if (this.Shape == eShape.Pyramid || this.Shape == eShape.PyramidToMax)
|
---|
452 | {
|
---|
453 | if (this.Direction == eDirection.Bar)
|
---|
454 | {
|
---|
455 | if (Grouping == eGrouping.Stacked)
|
---|
456 | {
|
---|
457 | return eChartType.PyramidBarStacked;
|
---|
458 | }
|
---|
459 | else if (Grouping == eGrouping.PercentStacked)
|
---|
460 | {
|
---|
461 | return eChartType.PyramidBarStacked100;
|
---|
462 | }
|
---|
463 | else if (Grouping == eGrouping.Clustered)
|
---|
464 | {
|
---|
465 | return eChartType.PyramidBarClustered;
|
---|
466 | }
|
---|
467 | }
|
---|
468 | else
|
---|
469 | {
|
---|
470 | if (Grouping == eGrouping.Stacked)
|
---|
471 | {
|
---|
472 | return eChartType.PyramidColStacked;
|
---|
473 | }
|
---|
474 | else if (Grouping == eGrouping.PercentStacked)
|
---|
475 | {
|
---|
476 | return eChartType.PyramidColStacked100;
|
---|
477 | }
|
---|
478 | else if (Grouping == eGrouping.Clustered)
|
---|
479 | {
|
---|
480 | return eChartType.PyramidColClustered;
|
---|
481 | }
|
---|
482 | else
|
---|
483 | {
|
---|
484 | return eChartType.PyramidCol;
|
---|
485 | }
|
---|
486 | }
|
---|
487 | }
|
---|
488 | #endregion
|
---|
489 | }
|
---|
490 | return base.GetChartType(name);
|
---|
491 | }
|
---|
492 | }
|
---|
493 | }
|
---|