/// <summary> /// Add a new series to this chart /// </summary> public void AddSeries(Series series) { int serCount = ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count(); if (serCount == MaxSeriesCount) throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!"); // Sourceman 16.04.2015 - Every Series needs to have an order and index element for being processed by Word 2013 series.Xml.AddFirst( new XElement(XName.Get("order", DocX.c.NamespaceName), new XAttribute(XName.Get("val"), (serCount + 1).ToString()))); series.Xml.AddFirst( new XElement(XName.Get("idx", DocX.c.NamespaceName), new XAttribute(XName.Get("val"), (serCount + 1).ToString()))); ChartXml.Add(series.Xml); }
private static void Chart3D() { Console.WriteLine("\tChart3D()"); // Create new document. using (DocX document = DocX.Create(@"docs\3DChart.docx")) { // Create chart. BarChart c = new BarChart(); c.View3D = true; // Create data. List<ChartData> company1 = ChartData.CreateCompanyList1(); // Create and add series Series s = new Series("Microsoft"); s.Color = Color.GreenYellow; s.Bind(company1, "Mounth", "Money"); c.AddSeries(s); // Insert chart into document document.InsertParagraph("3D Diagram").FontSize(20); document.InsertChart(c); document.Save(); } Console.WriteLine("\tCreated: docs\\3DChart.docx\n"); }
private static void PieChart() { Console.WriteLine("\tPieChart()"); // Create new document. using (DocX document = DocX.Create(@"docs\PieChart.docx")) { // Create chart. PieChart c = new PieChart(); c.AddLegend(ChartLegendPosition.Bottom, false); // Create data. List<ChartData> company2 = ChartData.CreateCompanyList2(); // Create and add series Series s = new Series("Apple"); s.Bind(company2, "Mounth", "Money"); c.AddSeries(s); // Insert chart into document document.InsertParagraph("Diagram").FontSize(20); document.InsertChart(c); document.Save(); } Console.WriteLine("\tCreated: docs\\PieChart.docx\n"); }
private static void LineChart() { Console.WriteLine("\tLineChart()"); // Create new document. using (DocX document = DocX.Create(@"docs\LineChart.docx")) { // Create chart. LineChart c = new LineChart(); c.AddLegend(ChartLegendPosition.Bottom, false); // Create data. List<ChartData> company1 = ChartData.CreateCompanyList1(); List<ChartData> company2 = ChartData.CreateCompanyList2(); // Create and add series Series s1 = new Series("Microsoft"); s1.Color = Color.GreenYellow; s1.Bind(company1, "Mounth", "Money"); c.AddSeries(s1); Series s2 = new Series("Apple"); s2.Bind(company2, "Mounth", "Money"); c.AddSeries(s2); // Insert chart into document document.InsertParagraph("Diagram").FontSize(20); document.InsertChart(c); document.Save(); } Console.WriteLine("\tCreated: docs\\LineChart.docx\n"); }
/// <summary> /// Add a new series to this chart /// </summary> public void AddSeries(Series series) { if (ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count() == MaxSeriesCount) throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!"); ChartXml.Add(series.Xml); }
private static void BarChart() { // Create new document. using (DocX document = DocX.Create(@"docs\BarChart.docx")) { // Create chart. BarChart c = new BarChart(); c.BarDirection = BarDirection.Column; c.BarGrouping = BarGrouping.Standard; c.GapWidth = 400; c.AddLegend(ChartLegendPosition.Bottom, false); // Create data. List<ChartData> company1 = ChartData.CreateCompanyList1(); List<ChartData> company2 = ChartData.CreateCompanyList2(); // Create and add series Series s1 = new Series("Microsoft"); s1.Color = Color.GreenYellow; s1.Bind(company1, "Mounth", "Money"); c.AddSeries(s1); Series s2 = new Series("Apple"); s2.Bind(company2, "Mounth", "Money"); c.AddSeries(s2); // Insert chart into document document.InsertParagraph("Diagram").FontSize(20); document.InsertChart(c); document.Save(); } }