* UILineChart:使用过程中Bug修改
This commit is contained in:
parent
8004aa04bd
commit
1cf50c2cf1
Binary file not shown.
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
@ -23,24 +23,24 @@ namespace Sunny.UI.Demo.Charts
|
|||||||
|
|
||||||
var series = option.AddSeries(new UILineSeries("Line1"));
|
var series = option.AddSeries(new UILineSeries("Line1"));
|
||||||
DateTime dt = new DateTime(2020, 10, 4);
|
DateTime dt = new DateTime(2020, 10, 4);
|
||||||
series.Add(dt.AddHours(0), 1.2);
|
// series.Add(dt.AddHours(0), 1.2);
|
||||||
series.Add(dt.AddHours(1), 2.2);
|
// series.Add(dt.AddHours(1), 2.2);
|
||||||
series.Add(dt.AddHours(2), 3.2);
|
// series.Add(dt.AddHours(2), 3.2);
|
||||||
series.Add(dt.AddHours(3), 4.2);
|
// series.Add(dt.AddHours(3), 4.2);
|
||||||
series.Add(dt.AddHours(4), 3.2);
|
// series.Add(dt.AddHours(4), 3.2);
|
||||||
series.Add(dt.AddHours(5), 2.2);
|
// series.Add(dt.AddHours(5), 2.2);
|
||||||
series.Symbol = UILinePointSymbol.Square;
|
series.Symbol = UILinePointSymbol.Square;
|
||||||
series.SymbolSize = 4;
|
series.SymbolSize = 4;
|
||||||
series.SymbolLineWidth = 2;
|
series.SymbolLineWidth = 2;
|
||||||
series.SymbolColor = Color.Red;
|
series.SymbolColor = Color.Red;
|
||||||
|
|
||||||
series = option.AddSeries(new UILineSeries("Line2", Color.Lime));
|
series = option.AddSeries(new UILineSeries("Line2", Color.Lime));
|
||||||
series.Add(dt.AddHours(3), 3.3);
|
// series.Add(dt.AddHours(3), 3.3);
|
||||||
series.Add(dt.AddHours(4), 2.3);
|
// series.Add(dt.AddHours(4), 2.3);
|
||||||
series.Add(dt.AddHours(5), 2.3);
|
// series.Add(dt.AddHours(5), 2.3);
|
||||||
series.Add(dt.AddHours(6), 1.3);
|
// series.Add(dt.AddHours(6), 1.3);
|
||||||
series.Add(dt.AddHours(7), 2.3);
|
// series.Add(dt.AddHours(7), 2.3);
|
||||||
series.Add(dt.AddHours(8), 4.3);
|
// series.Add(dt.AddHours(8), 4.3);
|
||||||
series.Symbol = UILinePointSymbol.Star;
|
series.Symbol = UILinePointSymbol.Star;
|
||||||
series.SymbolSize = 4;
|
series.SymbolSize = 4;
|
||||||
series.SymbolLineWidth = 2;
|
series.SymbolLineWidth = 2;
|
||||||
|
@ -213,6 +213,30 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawSeries(Graphics g, Color color, UILineSeries series)
|
||||||
|
{
|
||||||
|
if (series.Points.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (series.Points.Count == 1 && series.Symbol == UILinePointSymbol.None)
|
||||||
|
{
|
||||||
|
g.FillEllipse(color, series.Points[0].X - 2, series.Points[0].Y - 2, 4, 4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (Pen pen = new Pen(color, series.Width))
|
||||||
|
{
|
||||||
|
g.SetHighQuality();
|
||||||
|
if (series.Smooth)
|
||||||
|
g.DrawCurve(pen, series.Points.ToArray());
|
||||||
|
else
|
||||||
|
g.DrawLines(pen, series.Points.ToArray());
|
||||||
|
g.SetDefaultQuality();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawSeries(Graphics g)
|
private void DrawSeries(Graphics g)
|
||||||
{
|
{
|
||||||
if (YScale == null) return;
|
if (YScale == null) return;
|
||||||
@ -224,17 +248,7 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
Color color = series.Color;
|
Color color = series.Color;
|
||||||
if (!series.CustomColor) color = ChartStyle.GetColor(idx);
|
if (!series.CustomColor) color = ChartStyle.GetColor(idx);
|
||||||
|
DrawSeries(g, color, series);
|
||||||
using (Pen pen = new Pen(color, series.Width))
|
|
||||||
{
|
|
||||||
g.SetHighQuality();
|
|
||||||
if (series.Smooth)
|
|
||||||
g.DrawCurve(pen, series.Points.ToArray());
|
|
||||||
else
|
|
||||||
g.DrawLines(pen, series.Points.ToArray());
|
|
||||||
g.SetDefaultQuality();
|
|
||||||
}
|
|
||||||
|
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,42 +265,24 @@ namespace Sunny.UI
|
|||||||
Color color = series.Color;
|
Color color = series.Color;
|
||||||
if (!series.CustomColor) color = ChartStyle.GetColor(idx);
|
if (!series.CustomColor) color = ChartStyle.GetColor(idx);
|
||||||
|
|
||||||
using (Pen pen = new Pen(color, series.Width))
|
using (Graphics graphics = bmp.Graphics())
|
||||||
{
|
{
|
||||||
Graphics graphics = bmp.Graphics();
|
DrawSeries(graphics, color, series);
|
||||||
graphics.SetHighQuality();
|
|
||||||
if (series.Smooth)
|
|
||||||
graphics.DrawCurve(pen, series.Points.ToArray());
|
|
||||||
else
|
|
||||||
graphics.DrawLines(pen, series.Points.ToArray());
|
|
||||||
graphics.SetDefaultQuality();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LineOption.GreaterWarningArea != null)
|
if (LineOption.GreaterWarningArea != null)
|
||||||
{
|
{
|
||||||
using (Pen pen = new Pen(LineOption.GreaterWarningArea.Color, series.Width))
|
using (Graphics graphics = bmpGreater.Graphics())
|
||||||
{
|
{
|
||||||
Graphics graphics = bmpGreater.Graphics();
|
DrawSeries(graphics, LineOption.GreaterWarningArea.Color, series);
|
||||||
graphics.SetHighQuality();
|
|
||||||
if (series.Smooth)
|
|
||||||
graphics.DrawCurve(pen, series.Points.ToArray());
|
|
||||||
else
|
|
||||||
graphics.DrawLines(pen, series.Points.ToArray());
|
|
||||||
graphics.SetDefaultQuality();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LineOption.LessWarningArea != null)
|
if (LineOption.LessWarningArea != null)
|
||||||
{
|
{
|
||||||
using (Pen pen = new Pen(LineOption.LessWarningArea.Color, series.Width))
|
using (Graphics graphics = bmpLess.Graphics())
|
||||||
{
|
{
|
||||||
Graphics graphics = bmpLess.Graphics();
|
DrawSeries(graphics, LineOption.LessWarningArea.Color, series);
|
||||||
graphics.SetHighQuality();
|
|
||||||
if (series.Smooth)
|
|
||||||
graphics.DrawCurve(pen, series.Points.ToArray());
|
|
||||||
else
|
|
||||||
graphics.DrawLines(pen, series.Points.ToArray());
|
|
||||||
graphics.SetDefaultQuality();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,7 +292,6 @@ namespace Sunny.UI
|
|||||||
if (LineOption.GreaterWarningArea != null)
|
if (LineOption.GreaterWarningArea != null)
|
||||||
{
|
{
|
||||||
wTop = YScale.CalcYPixel(LineOption.GreaterWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
|
wTop = YScale.CalcYPixel(LineOption.GreaterWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
|
||||||
wTop = DrawOrigin.Y - wTop;
|
|
||||||
g.DrawImage(bmpGreater, new Rectangle(0, 0, Width, (int)wTop),
|
g.DrawImage(bmpGreater, new Rectangle(0, 0, Width, (int)wTop),
|
||||||
new Rectangle(0, 0, Width, (int)wTop), GraphicsUnit.Pixel);
|
new Rectangle(0, 0, Width, (int)wTop), GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
@ -304,7 +299,6 @@ namespace Sunny.UI
|
|||||||
if (LineOption.LessWarningArea != null)
|
if (LineOption.LessWarningArea != null)
|
||||||
{
|
{
|
||||||
wBottom = YScale.CalcYPixel(LineOption.LessWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
|
wBottom = YScale.CalcYPixel(LineOption.LessWarningArea.Value, DrawOrigin.Y, DrawSize.Height);
|
||||||
wBottom = DrawOrigin.Y - wBottom;
|
|
||||||
g.DrawImage(bmpLess, new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom),
|
g.DrawImage(bmpLess, new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom),
|
||||||
new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom), GraphicsUnit.Pixel);
|
new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom), GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
@ -398,7 +392,6 @@ namespace Sunny.UI
|
|||||||
foreach (var line in LineOption.YAxisScaleLines)
|
foreach (var line in LineOption.YAxisScaleLines)
|
||||||
{
|
{
|
||||||
float pos = YScale.CalcYPixel(line.Value, DrawOrigin.Y, DrawSize.Height);
|
float pos = YScale.CalcYPixel(line.Value, DrawOrigin.Y, DrawSize.Height);
|
||||||
pos = (Height - LineOption.Grid.Bottom - pos);
|
|
||||||
using (Pen pn = new Pen(line.Color, line.Size))
|
using (Pen pn = new Pen(line.Color, line.Size))
|
||||||
{
|
{
|
||||||
g.DrawLine(pn, DrawOrigin.X, pos, Width - LineOption.Grid.Right, pos);
|
g.DrawLine(pn, DrawOrigin.X, pos, Width - LineOption.Grid.Right, pos);
|
||||||
@ -426,6 +419,7 @@ namespace Sunny.UI
|
|||||||
selectPointsTemp.Clear();
|
selectPointsTemp.Clear();
|
||||||
foreach (var series in LineOption.Series.Values)
|
foreach (var series in LineOption.Series.Values)
|
||||||
{
|
{
|
||||||
|
if (series.DataCount == 0) continue;
|
||||||
if (series.GetNearestPoint(e.Location, 4, out double x, out double y, out int index))
|
if (series.GetNearestPoint(e.Location, 4, out double x, out double y, out int index))
|
||||||
{
|
{
|
||||||
UILineSelectPoint point = new UILineSelectPoint();
|
UILineSelectPoint point = new UILineSelectPoint();
|
||||||
|
@ -267,6 +267,11 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public bool GetNearestPoint(Point p, int offset, out double x, out double y, out int index)
|
public bool GetNearestPoint(Point p, int offset, out double x, out double y, out int index)
|
||||||
{
|
{
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
index = -1;
|
||||||
|
if (PointsX.Count == 0) return false;
|
||||||
|
|
||||||
index = PointsX.BinarySearchNearIndex(p.X);
|
index = PointsX.BinarySearchNearIndex(p.X);
|
||||||
if (p.X >= PointsX[index] - offset && p.X <= PointsX[index] + offset &&
|
if (p.X >= PointsX[index] - offset && p.X <= PointsX[index] + offset &&
|
||||||
p.Y >= PointsY[index] - offset && p.Y <= PointsY[index] + offset)
|
p.Y >= PointsY[index] - offset && p.Y <= PointsY[index] + offset)
|
||||||
@ -276,8 +281,6 @@ namespace Sunny.UI
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ namespace Sunny.UI
|
|||||||
/// <returns>最近值序号</returns>
|
/// <returns>最近值序号</returns>
|
||||||
public static int BinarySearchNearIndex<T>(this IList<T> list, T target) where T : IComparable
|
public static int BinarySearchNearIndex<T>(this IList<T> list, T target) where T : IComparable
|
||||||
{
|
{
|
||||||
|
if (list.Count == 0) return -1;
|
||||||
int i = 0, j = list.Count - 1;
|
int i = 0, j = list.Count - 1;
|
||||||
|
|
||||||
if (target.CompareTo(list[0]) == -1) return 0;
|
if (target.CompareTo(list[0]) == -1) return 0;
|
||||||
@ -166,7 +167,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public static T CheckLowerLimit<T>(this T obj, T lowerLimit) where T : IComparable
|
public static T CheckLowerLimit<T>(this T obj, T lowerLimit) where T : IComparable
|
||||||
{
|
{
|
||||||
return obj.CompareTo(lowerLimit) == -1 ? lowerLimit : obj;
|
return obj.CompareTo(lowerLimit) == -1 ? lowerLimit : obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T CheckUpperLimit<T>(this T obj, T upperLimit) where T : IComparable
|
public static T CheckUpperLimit<T>(this T obj, T upperLimit) where T : IComparable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user