diff --git a/Bin/SunnyUI.Demo.exe b/Bin/SunnyUI.Demo.exe index adee834f..1b7d9e7d 100644 Binary files a/Bin/SunnyUI.Demo.exe and b/Bin/SunnyUI.Demo.exe differ diff --git a/Bin/SunnyUI.dll b/Bin/SunnyUI.dll index 8fec2023..db72bebb 100644 Binary files a/Bin/SunnyUI.dll and b/Bin/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Charts/FLineChart.cs b/SunnyUI.Demo/Charts/FLineChart.cs index d018a3a2..d7dd4ba5 100644 --- a/SunnyUI.Demo/Charts/FLineChart.cs +++ b/SunnyUI.Demo/Charts/FLineChart.cs @@ -14,6 +14,7 @@ namespace Sunny.UI.Demo.Charts private void uiSymbolButton1_Click(object sender, EventArgs e) { UILineOption option = new UILineOption(); + option.ToolTip = new UIBarToolTip(); option.Title = new UITitle(); option.Title.Text = "SunnyUI"; option.Title.SubText = "LineChart"; @@ -46,35 +47,19 @@ namespace Sunny.UI.Demo.Charts series.SymbolColor = Color.Red; series.Smooth = true; - // option.XAxis.Min = new DateTimeInt64(dt.AddDays(-1)); - // option.XAxis.Max = new DateTimeInt64(dt.AddDays(1)); - // option.XAxis.MaxAuto = false; - // option.XAxis.MinAuto = false; - option.GreaterWarningArea = new UILineWarningArea(3.5); option.LessWarningArea = new UILineWarningArea(2.2, Color.Gold); option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 3.5 }); option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = 2.2 }); - option.XAxis.Name = "数值"; + option.XAxis.Name = "日期"; option.YAxis.Name = "数值"; + option.XAxis.AxisLabel.DateTimeFormat = DateTimeEx.DateTimeFormat; LineChart.SetOption(option); } - private void LineChart_PointValue(object sender, System.Collections.Generic.List points) - { - StringBuilder sb = new StringBuilder(); - foreach (var point in points) - { - sb.Append(point.Name + ", " + point.Index + ", " + point.X + ", " + point.Y); - sb.Append('\n'); - } - - Console.WriteLine(sb.ToString()); - } - private void uiImageButton1_Click(object sender, EventArgs e) { LineChart.ChartStyleType = UIChartStyleType.Default; @@ -89,5 +74,17 @@ namespace Sunny.UI.Demo.Charts { LineChart.ChartStyleType = UIChartStyleType.Dark; } + + private void LineChart_PointValue(object sender, UILineSelectPoint[] points) + { + StringBuilder sb = new StringBuilder(); + foreach (var point in points) + { + sb.Append(point.Name + ", " + point.Index + ", " + point.X + ", " + point.Y); + sb.Append('\n'); + } + + Console.WriteLine(sb.ToString()); + } } } diff --git a/SunnyUI/Charts/UIBarChartOption.cs b/SunnyUI/Charts/UIBarChartOption.cs index e918f47f..c6d7f297 100644 --- a/SunnyUI/Charts/UIBarChartOption.cs +++ b/SunnyUI/Charts/UIBarChartOption.cs @@ -102,7 +102,7 @@ namespace Sunny.UI public string Name { get; set; } - public UIAxisType Type { get; set; } + public UIAxisType Type { get; } /// /// 坐标轴的分割段数,需要注意的是这个分割段数只是个预估值 diff --git a/SunnyUI/Charts/UILineChart.cs b/SunnyUI/Charts/UILineChart.cs index 6ac46972..7a70bd0e 100644 --- a/SunnyUI/Charts/UILineChart.cs +++ b/SunnyUI/Charts/UILineChart.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; +using System.Text; using System.Windows.Forms; namespace Sunny.UI @@ -442,6 +443,7 @@ namespace Sunny.UI point.Index = index; point.X = x; point.Y = y; + point.Location = new Point((int)series.Points[index].X, (int)series.Points[index].Y); selectPointsTemp.Add(point); } } @@ -473,16 +475,60 @@ namespace Sunny.UI if (isNew) { selectPoints.Clear(); + StringBuilder sb = new StringBuilder(); + int idx = 0; foreach (var point in selectPointsTemp) { selectPoints.Add(point); + + if (idx > 0) sb.Append('\n'); + + sb.Append(point.Name); + sb.Append('\n'); + sb.Append(LineOption.XAxis.Name + ": "); + if (LineOption.XAxisType == UIAxisType.DateTime) + sb.Append(new DateTimeInt64(point.X).ToString(LineOption.XAxis.AxisLabel.DateTimeFormat)); + else + sb.Append(point.X.ToString("F" + LineOption.XAxis.AxisLabel.DecimalCount)); + sb.Append('\n'); + sb.Append(LineOption.YAxis.Name + ": " + point.Y.ToString("F" + LineOption.YAxis.AxisLabel.DecimalCount)); + idx++; } - PointValue?.Invoke(this, selectPoints); + if (LineOption.ToolTip != null) + { + if (sb.ToString().IsNullOrEmpty()) + { + tip.Visible = false; + } + else + { + using (Graphics g = this.CreateGraphics()) + { + SizeF sf = g.MeasureString(sb.ToString(), SubFont); + tip.Size = new Size((int)sf.Width + 4, (int)sf.Height + 4); + } + + int x = e.Location.X + 15; + int y = e.Location.Y + 20; + if (e.Location.X + 15 + tip.Width > Width - LineOption.Grid.Right) + x = e.Location.X - tip.Width - 2; + if (e.Location.Y + 20 + tip.Height > Height - LineOption.Grid.Bottom) + y = e.Location.Y - tip.Height - 2; + + tip.Left = x; + tip.Top = y; + + tip.Text = sb.ToString(); + if (!tip.Visible) tip.Visible = true; + } + } + + PointValue?.Invoke(this, selectPoints.ToArray()); } } - public delegate void OnPointValue(object sender, List points); + public delegate void OnPointValue(object sender, UILineSelectPoint[] points); public event OnPointValue PointValue; } diff --git a/SunnyUI/Charts/UILineChartOption.cs b/SunnyUI/Charts/UILineChartOption.cs index 77bea830..801f8c10 100644 --- a/SunnyUI/Charts/UILineChartOption.cs +++ b/SunnyUI/Charts/UILineChartOption.cs @@ -346,6 +346,8 @@ namespace Sunny.UI public double X { get; set; } public double Y { get; set; } + + public Point Location { get; set; } } public class UILineWarningArea