/// <summary> /// Adds a new series to the collection. /// </summary> public Series AddSeries() { Series series = new Series(); Add(series); return series; }
/// <summary> /// Parses the keyword «\series» inside a chart. /// </summary> private void ParseSeries(Series series) { // Syntax: // 1. \series{...} // 2. \series[...]{...} try { ReadCode(); if (Symbol == Symbol.BracketLeft) ParseAttributes(series); AssertSymbol(Symbol.BraceLeft, DomMsgID.MissingBraceLeft, GetSymbolText(Symbol.Series)); ReadCode(); // read beyond '{' bool fContinue = true; bool fFoundComma = true; while (fContinue) { switch (Symbol) { case Symbol.Eof: ThrowParserException(DomMsgID.UnexpectedEndOfFile); break; case Symbol.BraceRight: fContinue = false; break; case Symbol.Comma: fFoundComma = true; ReadCode(); break; case Symbol.Point: AssertCondition(fFoundComma, DomMsgID.MissingComma); ParsePoint(series.Add(0.0)); fFoundComma = false; break; case Symbol.Null: AssertCondition(fFoundComma, DomMsgID.MissingComma); series.AddBlank(); fFoundComma = false; ReadCode(); break; default: AssertCondition(fFoundComma, DomMsgID.MissingComma); series.Add(_scanner.GetTokenValueAsReal()); fFoundComma = false; ReadCode(); break; } } AssertSymbol(Symbol.BraceRight, DomMsgID.MissingBraceRight, GetSymbolText(Symbol.Series)); ReadCode(); // read beyond '}' } catch (DdlParserException pe) { ReportParserException(pe); AdjustToNextBlock(); } }
private static void DefineCharts(Document document, string person, Dictionary <string, string[]> groups, DataHandler datahandler) { List <double[]> list = new List <double[]>(); List <String> names = new List <string>(); YearInfo year = datahandler.GetYear(datahandler.FirstAvailableYear); /***** Calculate series data ******/ foreach (KeyValuePair <string, string[]> pair in groups) { String[] kgms = pair.Value; double[] percentages = new double[12]; names.Add(pair.Key); for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { percentages[i] = sm.PercentOfTotal(kgms); } else { percentages[i] = 0; } } else { percentages[i] = 0; } } list.Add(percentages); } double[] oms = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { oms[i] = sm.Omsaetning; } else { oms[i] = 0; } } else { oms[i] = 0; } } double[] ind = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { ind[i] = sm.Indtjening; } else { ind[i] = 0; } } else { ind[i] = 0; } } /***** Create chart for omsætning/indtjening series ******/ MigraDoc.DocumentObjectModel.Paragraph paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1"); Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(22); chart.Height = Unit.FromCentimeter(15); MigraDoc.DocumentObjectModel.Shapes.Charts.Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(oms); series.SetNull(); series.Name = "Omsætning"; series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(ind); series.SetNull(); series.Name = "Indtjening"; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" }); chart.XAxis.MajorTickMark = TickMarkType.Inside; chart.XAxis.Title.Caption = "MÅNEDER"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.LeftArea.AddLegend(); document.LastSection.Add(chart); /***** Create chart for KGM series ******/ paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1"); chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(22); chart.Height = Unit.FromCentimeter(15); for (int i = 0; i < list.Count; i++) { series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(list[i]); series.SetNull(); series.Name = names[i]; } xseries = chart.XValues.AddXSeries(); xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" }); chart.XAxis.MajorTickMark = TickMarkType.Inside; chart.XAxis.Title.Caption = "MÅNEDER"; chart.YAxis.TickLabels.Format = "#0%"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.LeftArea.AddLegend(); document.LastSection.Add(chart); }