From 43d3369365acb619aa9f581cd452184a2ad152fa Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 2 Jul 2023 19:50:10 +0800 Subject: [PATCH] =?UTF-8?q?*=20UILineChart:=20=E5=A2=9E=E5=8A=A0PointForma?= =?UTF-8?q?t=EF=BC=8C=E9=BC=A0=E6=A0=87=E9=80=89=E4=B8=AD=E5=80=BC?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Charts/UILineChart.cs | 56 ++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/SunnyUI/Charts/UILineChart.cs b/SunnyUI/Charts/UILineChart.cs index ac007a7e..1a953be4 100644 --- a/SunnyUI/Charts/UILineChart.cs +++ b/SunnyUI/Charts/UILineChart.cs @@ -45,6 +45,7 @@ * 2023-05-12: V3.3.6 增加了一种开关量曲线的显示方式 * 2023-05-14: V3.3.6 重构DrawString函数 * 2023-06-06: V3.3.7 修复X轴文字重叠问题 + * 2024-07-02: V3.3.9 增加PointFormat,鼠标选中值显示格式化事件 ******************************************************************************/ using System; @@ -854,32 +855,32 @@ namespace Sunny.UI if (idx > 0) sb.Append('\n'); - sb.Append(point.Series.Name); - sb.Append('\n'); - sb.Append(Option.XAxis.Name + ": "); - - string customlabel = ""; - //if (Option.XAxis.HaveCustomLabels) - //{ - // int ci = (int)((point.X - Option.XAxis.CustomLabels.Start) / Option.XAxis.CustomLabels.Interval); - // customlabel = Option.XAxis.CustomLabels.GetLabel(ci); - // sb.Append(customlabel); - //} - - if (customlabel.IsNullOrEmpty()) + if (PointFormat != null) { - if (Option.XAxisType == UIAxisType.DateTime) - sb.Append(new DateTimeInt64(point.X).ToString(point.Series.XAxisDateTimeFormat.IsValid() ? point.Series.XAxisDateTimeFormat : XScale.Format)); - else - sb.Append(point.X.ToString(point.Series.XAxisDecimalPlaces >= 0 ? "F" + point.Series.XAxisDecimalPlaces : XScale.Format)); + sb.Append(PointFormat(this, point)); } - - sb.Append('\n'); - - if (point.Series.IsY2) - sb.Append(Option.Y2Axis.Name + ": " + point.Y.ToString(point.Series.YAxisDecimalPlaces >= 0 ? "F" + point.Series.YAxisDecimalPlaces : Y2Scale.Format)); else - sb.Append(Option.YAxis.Name + ": " + point.Y.ToString(point.Series.YAxisDecimalPlaces >= 0 ? "F" + point.Series.YAxisDecimalPlaces : YScale.Format)); + { + sb.Append(point.Series.Name); + sb.Append('\n'); + sb.Append(Option.XAxis.Name + ": "); + + string customlabel = ""; + if (customlabel.IsNullOrEmpty()) + { + if (Option.XAxisType == UIAxisType.DateTime) + sb.Append(new DateTimeInt64(point.X).ToString(point.Series.XAxisDateTimeFormat.IsValid() ? point.Series.XAxisDateTimeFormat : XScale.Format)); + else + sb.Append(point.X.ToString(point.Series.XAxisDecimalPlaces >= 0 ? "F" + point.Series.XAxisDecimalPlaces : XScale.Format)); + } + + sb.Append('\n'); + + if (point.Series.IsY2) + sb.Append(Option.Y2Axis.Name + ": " + point.Y.ToString(point.Series.YAxisDecimalPlaces >= 0 ? "F" + point.Series.YAxisDecimalPlaces : Y2Scale.Format)); + else + sb.Append(Option.YAxis.Name + ": " + point.Y.ToString(point.Series.YAxisDecimalPlaces >= 0 ? "F" + point.Series.YAxisDecimalPlaces : YScale.Format)); + } idx++; } @@ -913,7 +914,10 @@ namespace Sunny.UI } } - PointValue?.Invoke(this, selectPoints.ToArray()); + if (selectPoints.Count > 0) + { + PointValue?.Invoke(this, selectPoints.ToArray()); + } } } else @@ -929,8 +933,12 @@ namespace Sunny.UI public delegate void OnPointValue(object sender, UILineSelectPoint[] points); + public delegate string OnPointFormat(object sender, UILineSelectPoint point); + public event OnPointValue PointValue; + public event OnPointFormat PointFormat; + private bool IsMouseDown; private Point StartPoint, StopPoint;