* UILineChart:增加ToolTip显示
This commit is contained in:
parent
26ce6ff7af
commit
3828b68355
Binary file not shown.
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
@ -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<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());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ namespace Sunny.UI
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public UIAxisType Type { get; set; }
|
||||
public UIAxisType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 坐标轴的分割段数,需要注意的是这个分割段数只是个预估值
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void OnPointValue(object sender, List<UILineSelectPoint> points);
|
||||
PointValue?.Invoke(this, selectPoints.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void OnPointValue(object sender, UILineSelectPoint[] points);
|
||||
|
||||
public event OnPointValue PointValue;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user