From c676e92fda28bfb705d715f63c83a49fd3c062f3 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 13 Nov 2024 11:05:53 +0800 Subject: [PATCH] =?UTF-8?q?*=20UILineChart:=20=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E9=BC=A0=E6=A0=87=E7=A7=BB=E4=B8=8A=E7=BB=98=E5=88=B6=E5=8D=81?= =?UTF-8?q?=E5=AD=97=E7=BA=BF=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Charts/UILineChart.cs | 30 +++++++++++++++++++++++++++-- SunnyUI/Charts/UILineChartOption.cs | 8 ++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/SunnyUI/Charts/UILineChart.cs b/SunnyUI/Charts/UILineChart.cs index fd37b39d..e8b238be 100644 --- a/SunnyUI/Charts/UILineChart.cs +++ b/SunnyUI/Charts/UILineChart.cs @@ -53,6 +53,7 @@ * 2023-10-20: V3.5.1 增加了绘制线的DashStyle样式 * 2023-11-22: V3.6.0 增加了区域选择范围相等时不执行事件 * 2024-07-01: V3.6.7 增加了Y轴自定义坐标显示 + * 2024-11-13: V3.7.2 增加了鼠标移上绘制十字线样式 ******************************************************************************/ using System; @@ -71,6 +72,10 @@ namespace Sunny.UI { protected bool NeedDraw; + [DefaultValue(MouseLineType.None)] + [Description("鼠标移上绘制十字线样式"), Category("SunnyUI")] + public MouseLineType MouseLine { get; set; } + /// /// 重载控件尺寸变更 /// @@ -98,7 +103,7 @@ namespace Sunny.UI NeedDraw = false; if (Option?.Series == null || Option.Series.Count == 0) return; if (DrawSize.Width <= 0 || DrawSize.Height <= 0) return; - CalcAxises(); + CalcAxes(); foreach (var series in Option.Series.Values) { @@ -137,7 +142,7 @@ namespace Sunny.UI protected UIScale YScale; protected UIScale Y2Scale; - protected void CalcAxises() + protected void CalcAxes() { if (Option.XAxisType == UIAxisType.DateTime) XScale = new UIDateScale(); @@ -289,6 +294,23 @@ namespace Sunny.UI DrawAxisScales(g); DrawPointSymbols(g); DrawOther(g); + + if (MousePoint.InRect(DrawRect)) + { + switch (MouseLine) + { + case MouseLineType.Horizontal: + g.DrawLine(Pens.Red, DrawRect.Left, MousePoint.Y, DrawRect.Right, MousePoint.Y); + break; + case MouseLineType.Vertical: + g.DrawLine(Pens.Red, MousePoint.X, DrawRect.Top, MousePoint.X, DrawRect.Bottom); + break; + case MouseLineType.Cross: + g.DrawLine(Pens.Red, DrawRect.Left, MousePoint.Y, DrawRect.Right, MousePoint.Y); + g.DrawLine(Pens.Red, MousePoint.X, DrawRect.Top, MousePoint.X, DrawRect.Bottom); + break; + } + } } private void DrawAxis(Graphics g) @@ -848,6 +870,7 @@ namespace Sunny.UI private readonly List selectPoints = new List(); private readonly List selectPointsTemp = new List(); + public Point MousePoint; /// /// 重载鼠标移动事件 /// @@ -1014,6 +1037,9 @@ namespace Sunny.UI } } + + MousePoint = e.Location; + if (MouseLine != MouseLineType.None) Invalidate(); } public delegate void OnPointValue(object sender, UILineSelectPoint[] points); diff --git a/SunnyUI/Charts/UILineChartOption.cs b/SunnyUI/Charts/UILineChartOption.cs index 42bfc941..8ffc0af0 100644 --- a/SunnyUI/Charts/UILineChartOption.cs +++ b/SunnyUI/Charts/UILineChartOption.cs @@ -33,6 +33,14 @@ using System.Linq; namespace Sunny.UI { + public enum MouseLineType + { + None, + Horizontal, + Vertical, + Cross + } + public enum UISeriesDataOrder { X,