From cea8e833e892200036dcf8709b9139b3792f442e Mon Sep 17 00:00:00 2001 From: bekodeg Date: Mon, 4 Nov 2024 13:04:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=BF=D0=B0=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/CustomPdfHistogram.cs | 4 +-- .../Cop.Borovkov.Var3/Models/ChartPoint.cs | 18 ++++++++++++ .../Models/PdfHistogramLineInfo.cs | 2 +- .../Models/PieChartModel/PdfHistogramData.cs | 4 +-- .../PIHelperSh.PdfCreater/PdfCreator.cs | 13 ++++++--- .../TestCustomComponents/Forms/Form2.cs | 28 +++++++++++++++---- 6 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ChartPoint.cs diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfHistogram.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfHistogram.cs index 84bf12c..b95aba0 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfHistogram.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomPdfHistogram.cs @@ -38,7 +38,7 @@ namespace Cop.Borovkov.Var3.Components foreach (var data in histogramInfo.Values) { - if (string.IsNullOrEmpty(data.Name) || data.Values == null || data.Values.Count() == 0) + if (string.IsNullOrEmpty(data.Name) || data.Points == null || data.Points.Count() == 0) throw new ArgumentException($"Набор данных для серии '{data.Name}' некорректен."); } @@ -58,7 +58,7 @@ namespace Cop.Borovkov.Var3.Components DataSet = histogramInfo.Values.Select(l => new PdfHistogramData() { DisplayName = l.Name, - Value = l.Values + Value = l.Points.Select(p => (p.Name, p.Value)) }).ToList() }); diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ChartPoint.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ChartPoint.cs new file mode 100644 index 0000000..148b689 --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/ChartPoint.cs @@ -0,0 +1,18 @@ +namespace Cop.Borovkov.Var3.Models +{ + /// + /// Точка + /// + public record ChartPoint + { + /// + /// Имя + /// + public required string Name { get; init; } = string.Empty; + + /// + /// Значение + /// + public required double Value { get; init; } + } +} diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistogramLineInfo.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistogramLineInfo.cs index bb04330..845036f 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistogramLineInfo.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Models/PdfHistogramLineInfo.cs @@ -10,6 +10,6 @@ /// /// Значения /// - public required IEnumerable Values { get; init; } + public required IEnumerable Points { get; init; } } } diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs index faac94a..b518631 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs +++ b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs @@ -15,7 +15,7 @@ namespace PIHelperSh.PdfCreator.Models.PieChartModel /// /// Значение варианта(по ним строят диаграмму) /// - public IEnumerable Value { get; set; } + public IEnumerable<(string Name, double Value)> Value { get; set; } /// /// Цвет области на диаграме. При null будет использоватсся выдача цветов по умолчанию) @@ -33,7 +33,7 @@ namespace PIHelperSh.PdfCreator.Models.PieChartModel /// /// /// - public PdfHistogramData(string displayName, IEnumerable value) + public PdfHistogramData(string displayName, IEnumerable<(string, double)> value) { DisplayName = displayName; Value = value; diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs index 1457499..e5dfad9 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs +++ b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs @@ -434,7 +434,9 @@ namespace PIHelperSh.PdfCreator row.Height = item.height; - for (int i = 0; i < maper.Count; i++) + ConfigurateCell(row.Cells[0], maper[0](item.value)?.ToString()!, header.RecordHorizontalAlignment, header.HeaderStyle); + + for (int i = 1; i < maper.Count; i++) { ConfigurateCell(row.Cells[i], maper[i](item.value)?.ToString()!, header.RecordHorizontalAlignment, header.RecordStyle); } @@ -520,14 +522,17 @@ namespace PIHelperSh.PdfCreator ConfiguratePieChart(chart, pieHistogram); XSeries xseries = chart.XValues.AddXSeries(); + foreach (var val in pieHistogram.DataSet.First().Value.Select(v => v.Name)) + xseries.Add(val); + foreach (var item in pieHistogram.DataSet) { Series series = chart.SeriesCollection.AddSeries(); + series.Name = item.DisplayName; - series.Add(item.Value.ToArray()); - xseries.Add(item.DisplayName); - + series.Add(item.Value.Select(v => v.Value).ToArray()); + if (item.Color.HasValue) { series.FillFormat.Color = new Color((uint)item.Color.Value.ToArgb()); diff --git a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs index f4d1e3e..2211f7a 100644 --- a/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs +++ b/Cop.Borovkov.Var3/TestCustomComponents/Forms/Form2.cs @@ -48,7 +48,7 @@ namespace TestCustomComponents.Forms { customPdfTableWithGrouping1.SaveToPdf(new() { - FilePath = @"E:\test\test.pdf", + FilePath = @"C:\test\test.pdf", Title = "Текст заголовка", Columns = [ new() { @@ -114,17 +114,35 @@ namespace TestCustomComponents.Forms { customPdfHistogram1.SaveToPdf(new() { - FilePath = @"E:\test\test.pdf", + FilePath = @"C:\test\test.pdf", DocumentTitle = "Текст заголовка", HistogramTitle = "Заголовок диограммы", Values = [ new(){ Name = "Линия1", - Values = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89], + Points = [ + new() { Name = "f3", Value = 2 }, + new() { Name = "f4", Value = 3 }, + new() { Name = "f5", Value = 5 }, + new() { Name = "f6", Value = 8 }, + new() { Name = "f7", Value = 13 }, + new() { Name = "f8", Value = 21 }, + new() { Name = "f9", Value = 34 }, + new() { Name = "f10", Value = 55 }, + new() { Name = "f11", Value = 89 }, + ], }, new(){ - Name = "Линия1", - Values = [1, 100, 10, 80, 30, 60, 50], + Name = "Линия2", + Points = [ + new() { Name = "r1", Value = 1 }, + new() { Name = "r2", Value = 100 }, + new() { Name = "r3", Value = 10 }, + new() { Name = "r4", Value = 80 }, + new() { Name = "r5", Value = 30 }, + new() { Name = "r6", Value = 60 }, + new() { Name = "r7", Value = 50 }, + ], } ], });