using Aspose.Words; using Aspose.Words.Drawing; using Aspose.Words.Drawing.Charts; using System.ComponentModel; using VisualCompLib.Components.SupportClasses; namespace VisualCompLib.Components { public partial class WordLineChart : Component { public WordLineChart() { InitializeComponent(); } public WordLineChart(IContainer container) { container.Add(this); InitializeComponent(); } public void AddLineChart(SimpleLineChart simpleLineChart) { if (!CheckData(simpleLineChart.DataList)) { throw new Exception("Не данные заполнены"); } Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Aspose.Words.Font font = builder.Font; font.Size = 24; font.Bold = true; font.Color = Color.Black; font.Name = "Times New Roman"; ParagraphFormat paragraphFormat = builder.ParagraphFormat; paragraphFormat.FirstLineIndent = 8; paragraphFormat.SpaceAfter = 24; paragraphFormat.Alignment = ParagraphAlignment.Center; paragraphFormat.KeepTogether = true; builder.Writeln(simpleLineChart.FileHeader); Shape shape = builder.InsertChart(ChartType.Line, 500, 270); Chart chart = shape.Chart; chart.Title.Text = simpleLineChart.LineChartName; ChartSeriesCollection seriesColl = chart.Series; Console.WriteLine(seriesColl.Count); seriesColl.Clear(); foreach (var data in simpleLineChart.DataList) { seriesColl.Add(data.NameSeries, data.NameData, data.Data ); } ChartLegend legend = chart.Legend; legend.Position = (LegendPosition)simpleLineChart.AreaLegend; legend.Overlay = true; doc.Save(simpleLineChart.FilePath); } static bool CheckData(List data) { foreach (var _data in data) { if (string.IsNullOrEmpty(_data.NameSeries) || string.IsNullOrEmpty(_data.NameData.ToString()) || string.IsNullOrEmpty(_data.Data.ToString())) { return false; } } return true; } } }