From 8f0f262d338b6d99e093b552f54a5c4910b227b2 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 17 Aug 2022 15:41:09 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIBarChart:=20=E5=A2=9E=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8F=AF=E4=B8=BANan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Charts/UIBarChart.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/SunnyUI/Charts/UIBarChart.cs b/SunnyUI/Charts/UIBarChart.cs index ed1510f9..782933fb 100644 --- a/SunnyUI/Charts/UIBarChart.cs +++ b/SunnyUI/Charts/UIBarChart.cs @@ -25,6 +25,7 @@ * 2022-07-29: V3.2.2 数据显示的小数位数重构调整至数据序列 Series.DecimalPlaces * 2022-07-30: V3.2.2 坐标轴的小数位数重构调整至坐标轴标签 AxisLabel.DecimalPlaces * 2022-08-10: V3.2.2 修复Y轴显示名称 + * 2022-08-17: V3.2.3 增加数据可为Nan ******************************************************************************/ using System; @@ -33,7 +34,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; -using System.Linq; using System.Windows.Forms; namespace Sunny.UI @@ -107,11 +107,21 @@ namespace Sunny.UI { if (series.Data.Count > 0) { - min = Math.Min(min, series.Data.Min()); - max = Math.Max(max, series.Data.Max()); + for (int i = 0; i < series.Data.Count; i++) + { + if (series.Data[i].IsNanOrInfinity()) continue; + min = Math.Min(min, series.Data[i]); + max = Math.Max(max, series.Data[i]); + } } } + if (min > max) + { + min = 0; + max = 1; + } + if (min > 0 && max > 0 && !Option.YAxis.Scale) min = 0; if (min < 0 && max < 0 && !Option.YAxis.Scale) max = 0; if (!Option.YAxis.MaxAuto) max = Option.YAxis.Max; @@ -468,6 +478,8 @@ namespace Sunny.UI if (Option.YAxis.AxisTick.Show) { g.DrawLine(ForeColor, DrawOrigin.X, labels[i], DrawOrigin.X - Option.YAxis.AxisTick.Length, labels[i]); + + if (YLabels[i].IsNanOrInfinity()) continue; if (!YLabels[i].EqualsDouble(0)) { using (Pen pn = new Pen(ForeColor))