2024-10-16 16:12:18 +04:00

108 lines
3.1 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 COP_1.cop_2.helpers;
using System.ComponentModel;
namespace COP_1.cop_2
{
public partial class WordDiagram : Component
{
public WordDiagram()
{
InitializeComponent();
}
public WordDiagram(IContainer container)
{
container.Add(this);
InitializeComponent();
}
string[] cats;
string[] doubs;
public void AddDiagram(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 = "Correction Tape";
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();
string[] cats;
double[] doubs;
foreach (var data in simpleLineChart.DataList)
{
cats = new string[simpleLineChart.DataList.Count];
doubs = new double[simpleLineChart.DataList.Count];
int i = 0;
foreach(var (name, value) in data.LineData)
{
cats[i] = name;
doubs[i] = value;
i++;
}
//var (name, values) = data.LineData;
seriesColl.Add(data.LineName, cats, doubs);
}
ChartLegend legend = chart.Legend;
legend.Position = (LegendPosition)simpleLineChart.AreaLegend;
legend.Overlay = true;
doc.Save(simpleLineChart.FilePath);
}
static bool CheckData(List<DataLineChart> data)
{
string[] cats = new string[data.Count];
double[] doubs = new double[data.Count];
foreach (var _data in data)
{
int i = 0;
foreach (var (name, value) in _data.LineData)
{
cats[i] = name;
doubs[i] = value;
i++;
}
if (string.IsNullOrEmpty(_data.LineName) || cats.Length == 0 || doubs.Length == 0)
return false;
}
return true;
}
}
}