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-12-30
|
---|
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 System.Collections;
|
---|
37 |
|
---|
38 | namespace OfficeOpenXml.Drawing.Chart
|
---|
39 | {
|
---|
40 | /// <summary>
|
---|
41 | /// A chart serie
|
---|
42 | /// </summary>
|
---|
43 | public class ExcelChartSerie : XmlHelper
|
---|
44 | {
|
---|
45 | internal ExcelChartSeries _chartSeries;
|
---|
46 | protected XmlNode _node;
|
---|
47 | protected XmlNamespaceManager _ns;
|
---|
48 | /// <summary>
|
---|
49 | /// Default constructor
|
---|
50 | /// </summary>
|
---|
51 | /// <param name="chartSeries">Parent collection</param>
|
---|
52 | /// <param name="ns">Namespacemanager</param>
|
---|
53 | /// <param name="node">Topnode</param>
|
---|
54 | /// <param name="isPivot">Is pivotchart</param>
|
---|
55 | internal ExcelChartSerie(ExcelChartSeries chartSeries, XmlNamespaceManager ns, XmlNode node, bool isPivot)
|
---|
56 | : base(ns,node)
|
---|
57 | {
|
---|
58 | _chartSeries = chartSeries;
|
---|
59 | _node=node;
|
---|
60 | _ns=ns;
|
---|
61 | SchemaNodeOrder = new string[] { "idx", "order","spPr", "tx", "marker", "trendline", "explosion","invertIfNegative", "dLbls", "cat", "val", "xVal", "yVal", "bubbleSize", "bubble3D", "smooth" };
|
---|
62 |
|
---|
63 | if (chartSeries.Chart.ChartType == eChartType.XYScatter ||
|
---|
64 | chartSeries.Chart.ChartType == eChartType.XYScatterLines ||
|
---|
65 | chartSeries.Chart.ChartType == eChartType.XYScatterLinesNoMarkers ||
|
---|
66 | chartSeries.Chart.ChartType == eChartType.XYScatterSmooth ||
|
---|
67 | chartSeries.Chart.ChartType == eChartType.XYScatterSmoothNoMarkers ||
|
---|
68 | chartSeries.Chart.ChartType == eChartType.Bubble ||
|
---|
69 | chartSeries.Chart.ChartType == eChartType.Bubble3DEffect)
|
---|
70 | {
|
---|
71 | _seriesTopPath = "c:yVal";
|
---|
72 | _xSeriesTopPath = "c:xVal";
|
---|
73 | }
|
---|
74 | else
|
---|
75 | {
|
---|
76 | _seriesTopPath = "c:val";
|
---|
77 | _xSeriesTopPath = "c:cat";
|
---|
78 | }
|
---|
79 | _seriesPath = string.Format(_seriesPath, _seriesTopPath);
|
---|
80 | _xSeriesPath = string.Format(_xSeriesPath, _xSeriesTopPath, isPivot ? "c:multiLvlStrRef" : "c:numRef");
|
---|
81 | }
|
---|
82 | internal void SetID(string id)
|
---|
83 | {
|
---|
84 | SetXmlNodeString("c:idx/@val",id);
|
---|
85 | SetXmlNodeString("c:order/@val", id);
|
---|
86 | }
|
---|
87 | const string headerPath="c:tx/c:v";
|
---|
88 | /// <summary>
|
---|
89 | /// Header for the serie.
|
---|
90 | /// </summary>
|
---|
91 | public string Header
|
---|
92 | {
|
---|
93 | get
|
---|
94 | {
|
---|
95 | return GetXmlNodeString(headerPath);
|
---|
96 | }
|
---|
97 | set
|
---|
98 | {
|
---|
99 | Cleartx();
|
---|
100 | SetXmlNodeString(headerPath, value);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | private void Cleartx()
|
---|
105 | {
|
---|
106 | var n = TopNode.SelectSingleNode("c:tx", NameSpaceManager);
|
---|
107 | if (n != null)
|
---|
108 | {
|
---|
109 | n.InnerXml = "";
|
---|
110 | }
|
---|
111 | }
|
---|
112 | const string headerAddressPath = "c:tx/c:strRef/c:f";
|
---|
113 | /// <summary>
|
---|
114 | /// Header address for the serie.
|
---|
115 | /// </summary>
|
---|
116 | public ExcelAddressBase HeaderAddress
|
---|
117 | {
|
---|
118 | get
|
---|
119 | {
|
---|
120 | string address = GetXmlNodeString(headerAddressPath);
|
---|
121 | if (address == "")
|
---|
122 | {
|
---|
123 | return null;
|
---|
124 | }
|
---|
125 | else
|
---|
126 | {
|
---|
127 | return new ExcelAddressBase(address);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | set
|
---|
131 | {
|
---|
132 | if ((value._fromCol != value._toCol && value._fromRow != value._toRow) || value.Addresses != null) //Single cell removed, allow row & column --> issue 15102.
|
---|
133 | {
|
---|
134 | throw (new ArgumentException("Address must be a row, column or single cell"));
|
---|
135 | }
|
---|
136 |
|
---|
137 | Cleartx();
|
---|
138 | SetXmlNodeString(headerAddressPath, ExcelCellBase.GetFullAddress(value.WorkSheet, value.Address));
|
---|
139 | SetXmlNodeString("c:tx/c:strRef/c:strCache/c:ptCount/@val", "0");
|
---|
140 | }
|
---|
141 | }
|
---|
142 | string _seriesTopPath;
|
---|
143 | string _seriesPath = "{0}/c:numRef/c:f";
|
---|
144 | /// <summary>
|
---|
145 | /// Set this to a valid address or the drawing will be invalid.
|
---|
146 | /// </summary>
|
---|
147 | public virtual string Series
|
---|
148 | {
|
---|
149 | get
|
---|
150 | {
|
---|
151 | return GetXmlNodeString(_seriesPath);
|
---|
152 | }
|
---|
153 | set
|
---|
154 | {
|
---|
155 | CreateNode(_seriesPath,true);
|
---|
156 | SetXmlNodeString(_seriesPath, ExcelCellBase.GetFullAddress(_chartSeries.Chart.WorkSheet.Name, value));
|
---|
157 |
|
---|
158 | XmlNode cache = TopNode.SelectSingleNode(string.Format("{0}/c:numRef/c:numCache",_seriesTopPath), _ns);
|
---|
159 | if (cache != null)
|
---|
160 | {
|
---|
161 | cache.ParentNode.RemoveChild(cache);
|
---|
162 | }
|
---|
163 |
|
---|
164 | if (_chartSeries.Chart.PivotTableSource != null)
|
---|
165 | {
|
---|
166 | SetXmlNodeString(string.Format("{0}/c:numRef/c:numCache", _seriesTopPath), "General");
|
---|
167 | }
|
---|
168 |
|
---|
169 | XmlNode lit = TopNode.SelectSingleNode(string.Format("{0}/c:numLit",_seriesTopPath), _ns);
|
---|
170 | if (lit != null)
|
---|
171 | {
|
---|
172 | lit.ParentNode.RemoveChild(lit);
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | }
|
---|
177 | string _xSeriesTopPath;
|
---|
178 | string _xSeriesPath = "{0}/{1}/c:f";
|
---|
179 | /// <summary>
|
---|
180 | /// Set an address for the horisontal labels
|
---|
181 | /// </summary>
|
---|
182 | public virtual string XSeries
|
---|
183 | {
|
---|
184 | get
|
---|
185 | {
|
---|
186 | return GetXmlNodeString(_xSeriesPath);
|
---|
187 | }
|
---|
188 | set
|
---|
189 | {
|
---|
190 | CreateNode(_xSeriesPath, true);
|
---|
191 | SetXmlNodeString(_xSeriesPath, ExcelCellBase.GetFullAddress(_chartSeries.Chart.WorkSheet.Name, value));
|
---|
192 |
|
---|
193 | XmlNode cache = TopNode.SelectSingleNode(string.Format("{0}/c:numRef/c:numCache",_xSeriesTopPath), _ns);
|
---|
194 | if (cache != null)
|
---|
195 | {
|
---|
196 | cache.ParentNode.RemoveChild(cache);
|
---|
197 | }
|
---|
198 |
|
---|
199 | XmlNode lit = TopNode.SelectSingleNode(string.Format("{0}/c:numLit",_xSeriesTopPath), _ns);
|
---|
200 | if (lit != null)
|
---|
201 | {
|
---|
202 | lit.ParentNode.RemoveChild(lit);
|
---|
203 | }
|
---|
204 | }
|
---|
205 | }
|
---|
206 | ExcelChartTrendlineCollection _trendLines = null;
|
---|
207 | /// <summary>
|
---|
208 | /// Access to the trendline collection
|
---|
209 | /// </summary>
|
---|
210 | public ExcelChartTrendlineCollection TrendLines
|
---|
211 | {
|
---|
212 | get
|
---|
213 | {
|
---|
214 | if (_trendLines == null)
|
---|
215 | {
|
---|
216 | _trendLines = new ExcelChartTrendlineCollection(this);
|
---|
217 | }
|
---|
218 | return _trendLines;
|
---|
219 | }
|
---|
220 | }
|
---|
221 | }
|
---|
222 | }
|
---|