58 lines
1.2 KiB
C#
58 lines
1.2 KiB
C#
using ExcelComponents.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ExcelComponents
|
|
{
|
|
public partial class ExcelLinearChart : Component
|
|
{
|
|
ExcelBuilder builder = new ExcelBuilder();
|
|
public ExcelLinearChart()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public ExcelLinearChart(IContainer container)
|
|
{
|
|
container.Add(this);
|
|
|
|
InitializeComponent();
|
|
}
|
|
private static bool ConfigIsCorrect(LinearChartConfig config)
|
|
{
|
|
if (config == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (string.IsNullOrEmpty(config.FilePath) || File.Exists(config.FilePath))
|
|
{
|
|
return false;
|
|
}
|
|
foreach(var item in config.Data)
|
|
{
|
|
if (config.Labels.Length != item.Item2.Length)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
public void GenChart(LinearChartConfig config)
|
|
{
|
|
if (!ConfigIsCorrect(config))
|
|
{
|
|
return;
|
|
}
|
|
builder.CreateDocument();
|
|
builder.InsertText(1, 1, config.Title);
|
|
builder.InsertLinearChart(config.ChartTitle, config.Data, config.Labels, config.LegendPosition);
|
|
builder.SaveDocument(config.FilePath);
|
|
}
|
|
}
|
|
}
|