From c7b0db4fa318e90c7f98f72f03673d6a161f54f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Thu, 2 Nov 2023 09:12:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D1=81=20=D0=BC=D0=B5=D0=BD=D1=8C=D1=88=D0=B8=D0=BC=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B4=D0=B8?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsProject/WinFormsLibrary/CircleDiagram.cs | 14 +++++++++++++- .../WinFormsLibrary/WinFormsLibrary.csproj | 1 + WinFormsProject/WinFormsProject/Form2.cs | 10 ++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/WinFormsProject/WinFormsLibrary/CircleDiagram.cs b/WinFormsProject/WinFormsLibrary/CircleDiagram.cs index e515ef6..621a816 100644 --- a/WinFormsProject/WinFormsLibrary/CircleDiagram.cs +++ b/WinFormsProject/WinFormsLibrary/CircleDiagram.cs @@ -66,9 +66,21 @@ namespace WinFormsLibrary foreach (var data in simpleCircleDiagram.DataList) { - seriesColl.Add(data.NameSeries, simpleCircleDiagram.NameData ,data.Data); + int count = Math.Min(simpleCircleDiagram.NameData.Length, data.Data.Length); + + // Создаем временный массив для данных и имен, содержащий только необходимое количество элементов. + string seriesNames = data.NameSeries; + double[] seriesData = data.Data.Take(count).ToArray(); + string[] categoryNames = simpleCircleDiagram.NameData.Take(count).ToArray(); + + // Добавляем только непустые серии с данными в график. + if (seriesData.Length > 0) + { + seriesColl.Add(seriesNames, categoryNames, seriesData); + } } + ChartLegend legend = chart.Legend; legend.Position = (LegendPosition)simpleCircleDiagram.AreaLegend; diff --git a/WinFormsProject/WinFormsLibrary/WinFormsLibrary.csproj b/WinFormsProject/WinFormsLibrary/WinFormsLibrary.csproj index 462f673..42ca00a 100644 --- a/WinFormsProject/WinFormsLibrary/WinFormsLibrary.csproj +++ b/WinFormsProject/WinFormsLibrary/WinFormsLibrary.csproj @@ -5,6 +5,7 @@ enable true enable + True diff --git a/WinFormsProject/WinFormsProject/Form2.cs b/WinFormsProject/WinFormsProject/Form2.cs index c7de8a5..8665242 100644 --- a/WinFormsProject/WinFormsProject/Form2.cs +++ b/WinFormsProject/WinFormsProject/Form2.cs @@ -63,8 +63,6 @@ namespace WinFormsProject new int[] { 0, 1, 2 } }; - - List columnDefinitions = new List { new ColumnDefinition { Header = "Образование", PropertyName = "Eduction", Weight = 35 }, @@ -119,11 +117,11 @@ namespace WinFormsProject { try { - double[] profit1 = { 300, 440, 270 }; - double[] profit2 = { 500, 620, 310 }; - double[] profit3 = { 420, 189, 430 }; + double[] profit1 = { 300, 324, 500 }; + double[] profit2 = { 500, 620, 310 }; + double[] profit3 = { 420, 189, 420 }; SimpleCircleDiagram simpleCircleDiagram = new(dialog.FileName, "Третье задание", "График прибыли", EnumAreaLegend.Right, new List { - new DataCircleDiagram("Компания 1", profit1), new DataCircleDiagram("Компания 2", profit2), new DataCircleDiagram("Компания 3", profit3), + new DataCircleDiagram("Компания 1", profit1), new DataCircleDiagram("Компания 2", profit2), new DataCircleDiagram("Компания 3", profit3) }); simpleCircleDiagram.NameData = new string[] { "Январь", "Февраль", "Март" };