internal ExcelChartSeries(ExcelChart chart, XmlNamespaceManager ns, XmlNode node, bool isPivot) : base(ns,node) { _ns = ns; _chart=chart; _node=node; _isPivot = isPivot; SchemaNodeOrder = new string[] { "view3D", "plotArea", "barDir", "grouping", "scatterStyle", "varyColors", "ser", "explosion", "dLbls", "firstSliceAng", "holeSize", "shape", "legend", "axId" }; foreach(XmlNode n in node.SelectNodes("c:ser",ns)) { ExcelChartSerie s; if (chart.ChartNode.LocalName == "scatterChart") { s = new ExcelScatterChartSerie(this, ns, n, isPivot); } else if (chart.ChartNode.LocalName == "lineChart") { s = new ExcelLineChartSerie(this, ns, n, isPivot); } else if (chart.ChartNode.LocalName == "pieChart" || chart.ChartNode.LocalName == "ofPieChart" || chart.ChartNode.LocalName == "pie3DChart" || chart.ChartNode.LocalName == "doughnutChart") { s = new ExcelPieChartSerie(this, ns, n, isPivot); } else { s = new ExcelChartSerie(this, ns, n, isPivot); } _list.Add(s); } }
public static void SetSeriesLineColor(this ExcelChart chart, int serieIdx, string color, double lineWidth = 2.25, eLineStyle lineStyle = eLineStyle.Solid) { ExcelLineChartSerie serie = (ExcelLineChartSerie)chart.Series[serieIdx]; serie.LineColor = ColorTranslator.FromHtml(color); serie.LineWidth = lineWidth; serie.Border.LineStyle = lineStyle; }
private void AddRaceProgress(ExcelWorksheet sheet, SessionSummary sessionSummary) { int maxLaps = sessionSummary.Drivers.Select(x => x.Laps.Count).Max(); List <Driver> orderedDrivers = sessionSummary.Drivers.OrderBy(x => x.Laps.LastOrDefault()?.LapEndSnapshot.PlayerData.Position).ToList(); int startRow = 100; int startColumn = 1; sheet.Cells[startRow + 1, startColumn].Value = "Start"; GenerateNumberColumn(sheet, new ExcelCellAddress(startRow + 2, startColumn), maxLaps); GenerateDriversRow(sheet, new ExcelCellAddress(startRow, startColumn + 1), orderedDrivers.Select(x => x.DriverName)); ExcelCellAddress startAddress = new ExcelCellAddress(startRow + 1, startColumn + 1); orderedDrivers.ForEach( x => { GenerateLapsPositionColumn(sheet, startAddress, x.Laps, maxLaps); startAddress = new ExcelCellAddress(startAddress.Row, startAddress.Column + 1); }); ExcelLineChart chart = (ExcelLineChart)sheet.Drawings.AddChart("Race Progress", eChartType.LineMarkers); chart.SetPosition(0, 0, 0, 0); int currentColumn = 2; orderedDrivers.ForEach( x => { ExcelLineChartSerie series = (ExcelLineChartSerie)chart.Series.Add(ExcelCellBase.GetAddress(startRow + 1, currentColumn, startRow + 1 + maxLaps, currentColumn), ExcelCellBase.GetAddress(startRow + 1, 1, startRow + 1 + maxLaps, 1)); series.Header = x.DriverName; currentColumn++; }); chart.ShowDataLabelsOverMaximum = false; chart.DataLabel.ShowValue = true; chart.ShowHiddenData = true; chart.Axis[1].MinValue = 0; chart.Axis[1].TickLabelPosition = eTickLabelPosition.NextTo; chart.Axis[1].MajorUnit = 1; chart.Axis[1].MinorUnit = 1; chart.Axis[1].Orientation = eAxisOrientation.MaxMin; chart.Axis[1].MaxValue = orderedDrivers.Count; chart.SetSize(70 * maxLaps, 30 * orderedDrivers.Count); chart.Axis[0].MajorUnit = 1; chart.Axis[0].MinorUnit = 1; chart.Title.Text = "Race Progress"; }
private ExcelChartSerie AddSeries(string SeriesAddress, string XSeriesAddress) { XmlElement ser = _node.OwnerDocument.CreateElement("ser", ExcelPackage.schemaChart); XmlNodeList node = _node.SelectNodes("c:ser", _ns); if (node.Count > 0) { _node.InsertAfter(ser, node[node.Count-1]); } else { InserAfter(_node, "c:varyColors,c:grouping,c:barDir,c:scatterStyle", ser); } int idx = FindIndex(); ser.InnerXml = string.Format("<c:idx val=\"{1}\" /><c:order val=\"{1}\" /><c:tx><c:strRef><c:f></c:f><c:strCache><c:ptCount val=\"1\" /></c:strCache></c:strRef></c:tx>{5}{0}{2}{3}{4}", AddExplosion(Chart.ChartType), idx, AddScatterPoint(Chart.ChartType), AddAxisNodes(Chart.ChartType), AddSmooth(Chart.ChartType), AddMarker(Chart.ChartType)); ExcelChartSerie serie; switch (Chart.ChartType) { case eChartType.XYScatter: case eChartType.XYScatterLines: case eChartType.XYScatterLinesNoMarkers: case eChartType.XYScatterSmooth: case eChartType.XYScatterSmoothNoMarkers: serie = new ExcelScatterChartSerie(this, NameSpaceManager, ser, _isPivot); break; case eChartType.Pie: case eChartType.Pie3D: case eChartType.PieExploded: case eChartType.PieExploded3D: case eChartType.PieOfPie: case eChartType.Doughnut: case eChartType.DoughnutExploded: case eChartType.BarOfPie: serie = new ExcelPieChartSerie(this, NameSpaceManager, ser, _isPivot); break; case eChartType.Line: case eChartType.LineMarkers: case eChartType.LineMarkersStacked: case eChartType.LineMarkersStacked100: case eChartType.LineStacked: case eChartType.LineStacked100: serie = new ExcelLineChartSerie(this, NameSpaceManager, ser, _isPivot); if (Chart.ChartType == eChartType.LineMarkers || Chart.ChartType == eChartType.LineMarkersStacked || Chart.ChartType == eChartType.LineMarkersStacked100) { ((ExcelLineChartSerie)serie).Marker = eMarkerStyle.Square; } ((ExcelLineChartSerie)serie).Smooth = ((ExcelLineChart)Chart).Smooth; break; default: serie = new ExcelChartSerie(this, NameSpaceManager, ser, _isPivot); break; } serie.Series = SeriesAddress; serie.XSeries = XSeriesAddress; _list.Add(serie); return serie; }