2023-10-18 21:58:51 +04:00
|
|
|
|
using Aspose.Words.Drawing.Charts;
|
|
|
|
|
using Aspose.Words;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using WinFormsLibrary.SupportClasses;
|
|
|
|
|
using Aspose.Words.Drawing;
|
|
|
|
|
|
|
|
|
|
namespace WinFormsLibrary
|
|
|
|
|
{
|
|
|
|
|
public partial class CircleDiagram : Component
|
|
|
|
|
{
|
|
|
|
|
public CircleDiagram()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CircleDiagram(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container.Add(this);
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddCircleDiagram(SimpleCircleDiagram simpleCircleDiagram)
|
|
|
|
|
{
|
|
|
|
|
if (!CheckData(simpleCircleDiagram.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(simpleCircleDiagram.FileHeader);
|
|
|
|
|
|
|
|
|
|
Shape shape = builder.InsertChart(ChartType.Pie, 500, 270);
|
|
|
|
|
|
|
|
|
|
Chart chart = shape.Chart;
|
|
|
|
|
|
|
|
|
|
chart.Title.Text = simpleCircleDiagram.CircleDiagramName;
|
|
|
|
|
|
|
|
|
|
ChartSeries series = chart.Series[0];
|
|
|
|
|
|
|
|
|
|
ChartSeriesCollection seriesColl = chart.Series;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(seriesColl.Count);
|
|
|
|
|
|
|
|
|
|
seriesColl.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var data in simpleCircleDiagram.DataList)
|
|
|
|
|
{
|
2023-11-01 19:53:04 +04:00
|
|
|
|
seriesColl.Add(data.NameSeries, simpleCircleDiagram.NameData ,data.Data);
|
2023-10-18 21:58:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChartLegend legend = chart.Legend;
|
|
|
|
|
|
|
|
|
|
legend.Position = (LegendPosition)simpleCircleDiagram.AreaLegend;
|
|
|
|
|
|
|
|
|
|
legend.Overlay = true;
|
|
|
|
|
|
|
|
|
|
doc.Save(simpleCircleDiagram.FilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool CheckData(List<DataCircleDiagram> data)
|
|
|
|
|
{
|
|
|
|
|
foreach (var _data in data)
|
|
|
|
|
{
|
2023-11-01 19:53:04 +04:00
|
|
|
|
if (string.IsNullOrEmpty(_data.NameSeries) || string.IsNullOrEmpty(_data.Data.ToString()))
|
2023-10-18 21:58:51 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|