Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ExportSymbolicDataAnalysisSolutions/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/Drawing/Chart/ExcelChartSerie.cs @ 11733

Last change on this file since 11733 was 9580, checked in by sforsten, 12 years ago

#1730:

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