PIbd-32_Turner_I.A._COP_10/COP/VisualCompLib/Components/WordLineChart.cs
2023-10-11 21:23:26 +04:00

85 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<DataLineChart> 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;
}
}
}