94 lines
2.6 KiB
C#
94 lines
2.6 KiB
C#
|
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)
|
|||
|
{
|
|||
|
seriesColl.Add(data.NameSeries, data.NameData, data.Data);
|
|||
|
}
|
|||
|
|
|||
|
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)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(_data.NameData.ToString()) || string.IsNullOrEmpty(_data.Data.ToString()))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|