Zhelovanov_Dmitrii_COP/KOP_Labs/NonVisualComponents/WordHistogramm.cs

89 lines
2.0 KiB
C#

using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Drawing.Charts;
using KOP_Labs.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KOP_Labs.NonVisualComponents
{
public partial class WordHistogramm : Component
{
public WordHistogramm()
{
InitializeComponent();
}
public WordHistogramm(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateHistogramm(MyHistogramm myHistogramm)
{
if(CheckData(myHistogramm._dataList)) {
return;
}
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Font font = builder.Font;
font.Size = 14;
font.Bold = true;
font.Color = System.Drawing.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(myHistogramm._fileHeader);
Shape shape = builder.InsertChart(ChartType.Column, 500, 270);
Chart chart = shape.Chart;
chart.Title.Text = myHistogramm._fileHeader;
ChartSeriesCollection seriesColl = chart.Series;
seriesColl.Clear();
string[] categories = new string[] { myHistogramm._dataList[0]._nameData };
foreach (var data in myHistogramm._dataList)
{
seriesColl.Add(data._nameData, categories, new double[] { data._data });
}
ChartLegend legend = chart.Legend;
legend.Position = (LegendPosition)myHistogramm._legends;
legend.Overlay = true;
doc.Save(myHistogramm._filePath);
}
private bool CheckData(List<DataHistogramm> data)
{
foreach (var _data in data)
{
if (string.IsNullOrEmpty(_data._nameSeries) || string.IsNullOrEmpty(_data._data.ToString()))
{
return false;
}
}
return true;
}
}
}