* UILineChart: 增加坐标线、图线边框等是否显示的设置

This commit is contained in:
Sunny 2021-12-31 00:09:11 +08:00
parent f8a500a65a
commit 4205e98dbc
5 changed files with 67 additions and 30 deletions

Binary file not shown.

View File

@ -153,6 +153,8 @@ namespace Sunny.UI
public List<string> Data = new List<string>(); public List<string> Data = new List<string>();
public bool ShowGridLine { get; set; } = true;
public void Clear() public void Clear()
{ {
Data.Clear(); Data.Clear();

View File

@ -25,6 +25,7 @@
* 2021-10-02: V3.0.8 Nan * 2021-10-02: V3.0.8 Nan
* 2021-10-14: V3.0.8 线 * 2021-10-14: V3.0.8 线
* 2021-12-30: V3.0.9 Y坐标轴 * 2021-12-30: V3.0.9 Y坐标轴
* 2021-12-31: V3.0.9 线线
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -162,11 +163,6 @@ namespace Sunny.UI
UIOption option = BaseOption ?? EmptyOption; UIOption option = BaseOption ?? EmptyOption;
return (UILineOption)option; return (UILineOption)option;
} }
// set
// {
// SetOption(value);
// }
} }
protected override void CreateEmptyOption() protected override void CreateEmptyOption()
@ -221,12 +217,8 @@ namespace Sunny.UI
bmpLess = new Bitmap(Width, Height); bmpLess = new Bitmap(Width, Height);
} }
// if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow) DrawToolTip(g);
DrawTitle(g, Option.Title); DrawTitle(g, Option.Title);
DrawSeries(g); DrawSeries(g);
// if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line) DrawToolTip(g);
DrawLegend(g, Option.Legend); DrawLegend(g, Option.Legend);
DrawAxis(g); DrawAxis(g);
DrawAxisScales(g); DrawAxisScales(g);
@ -236,17 +228,33 @@ namespace Sunny.UI
private void DrawAxis(Graphics g) private void DrawAxis(Graphics g)
{ {
g.DrawRectangle(ForeColor, Option.Grid.Left, Option.Grid.Top, DrawSize.Width, DrawSize.Height); if (Option.Grid.LeftShow)
g.DrawLine(ForeColor, Option.Grid.Left, Option.Grid.Top, Option.Grid.Left, Height - Option.Grid.Bottom);
if (Option.Grid.TopShow)
g.DrawLine(ForeColor, Option.Grid.Left, Option.Grid.Top, Width - Option.Grid.Right, Option.Grid.Top);
if (Option.Grid.RightShow)
g.DrawLine(ForeColor, Width - Option.Grid.Right, Option.Grid.Top, Width - Option.Grid.Right, Height - Option.Grid.Bottom);
if (Option.Grid.BottomShow)
g.DrawLine(ForeColor, Option.Grid.Left, Height - Option.Grid.Bottom, Width - Option.Grid.Right, Height - Option.Grid.Bottom);
float zeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height); float zeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height);
if (zeroPos > Option.Grid.Top && zeroPos < Height - Option.Grid.Bottom) if (zeroPos > Option.Grid.Top && zeroPos < Height - Option.Grid.Bottom)
{
if (Option.ShowZeroLine)
{ {
g.DrawLine(ForeColor, DrawOrigin.X, zeroPos, DrawOrigin.X + DrawSize.Width, zeroPos); g.DrawLine(ForeColor, DrawOrigin.X, zeroPos, DrawOrigin.X + DrawSize.Width, zeroPos);
} }
if (Option.ShowZeroValue)
{
SizeF sf = g.MeasureString("0", TempFont);
g.DrawString("0", TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, zeroPos - sf.Height / 2.0f);
}
}
if (XScale == null || YScale == null || Y2Scale == null) return; if (XScale == null || YScale == null || Y2Scale == null) return;
//X Tick //X Tick
if (Option.XAxis.AxisTick.Show)
{ {
float[] labels = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width); float[] labels = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width);
for (int i = 0; i < labels.Length; i++) for (int i = 0; i < labels.Length; i++)
@ -277,10 +285,16 @@ namespace Sunny.UI
} }
if (Option.XAxis.AxisTick.Show)
{
g.DrawLine(ForeColor, x, DrawOrigin.Y, x, DrawOrigin.Y + Option.XAxis.AxisTick.Length); g.DrawLine(ForeColor, x, DrawOrigin.Y, x, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
}
if (x.Equals(DrawOrigin.X)) continue; if (x.Equals(DrawOrigin.X)) continue;
if (x.Equals(DrawOrigin.X + DrawSize.Width)) continue; if (x.Equals(DrawOrigin.X + DrawSize.Width)) continue;
if (Option.XAxis.ShowGridLine)
{
using (Pen pn = new Pen(ForeColor)) using (Pen pn = new Pen(ForeColor))
{ {
pn.DashStyle = DashStyle.Dash; pn.DashStyle = DashStyle.Dash;
@ -288,6 +302,7 @@ namespace Sunny.UI
g.DrawLine(pn, x, DrawOrigin.Y, x, Option.Grid.Top); g.DrawLine(pn, x, DrawOrigin.Y, x, Option.Grid.Top);
} }
} }
}
SizeF sfName = g.MeasureString(Option.XAxis.Name, TempFont); SizeF sfName = g.MeasureString(Option.XAxis.Name, TempFont);
g.DrawString(Option.XAxis.Name, TempFont, ForeColor, g.DrawString(Option.XAxis.Name, TempFont, ForeColor,
@ -296,7 +311,6 @@ namespace Sunny.UI
} }
//Y Tick //Y Tick
if (Option.YAxis.AxisTick.Show)
{ {
float[] labels = YScale.CalcYPixels(YLabels, DrawOrigin.Y, DrawSize.Height); float[] labels = YScale.CalcYPixels(YLabels, DrawOrigin.Y, DrawSize.Height);
float widthMax = 0; float widthMax = 0;
@ -305,18 +319,25 @@ namespace Sunny.UI
float y = labels[i]; float y = labels[i];
if (y < Option.Grid.Top || y > Height - Option.Grid.Bottom) continue; if (y < Option.Grid.Top || y > Height - Option.Grid.Bottom) continue;
if (Option.YAxis.AxisLabel.Show)
{
string label = YLabels[i].ToString(YScale.Format); string label = YLabels[i].ToString(YScale.Format);
SizeF sf = g.MeasureString(label, TempFont); SizeF sf = g.MeasureString(label, TempFont);
widthMax = Math.Max(widthMax, sf.Width); widthMax = Math.Max(widthMax, sf.Width);
if (Option.YAxis.AxisLabel.Show)
{
g.DrawString(label, TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f); g.DrawString(label, TempFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
} }
if (Option.YAxis.AxisTick.Show)
{
g.DrawLine(ForeColor, DrawOrigin.X, y, DrawOrigin.X - Option.YAxis.AxisTick.Length, y); g.DrawLine(ForeColor, DrawOrigin.X, y, DrawOrigin.X - Option.YAxis.AxisTick.Length, y);
}
if (y.Equals(DrawOrigin.Y)) continue; if (y.Equals(DrawOrigin.Y)) continue;
if (y.Equals(DrawOrigin.X - DrawSize.Height)) continue; if (y.Equals(DrawOrigin.X - DrawSize.Height)) continue;
if (Option.YAxis.ShowGridLine)
{
using (Pen pn = new Pen(ForeColor)) using (Pen pn = new Pen(ForeColor))
{ {
pn.DashStyle = DashStyle.Dash; pn.DashStyle = DashStyle.Dash;
@ -324,6 +345,7 @@ namespace Sunny.UI
g.DrawLine(pn, DrawOrigin.X, y, Width - Option.Grid.Right, y); g.DrawLine(pn, DrawOrigin.X, y, Width - Option.Grid.Right, y);
} }
} }
}
SizeF sfName = g.MeasureString(Option.YAxis.Name, TempFont); SizeF sfName = g.MeasureString(Option.YAxis.Name, TempFont);
float xx = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f; float xx = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f;
@ -332,7 +354,7 @@ namespace Sunny.UI
} }
//Y2 Tick //Y2 Tick
if (Option.HaveY2 && Option.Y2Axis.AxisTick.Show) if (Option.HaveY2)
{ {
float[] labels = Y2Scale.CalcYPixels(Y2Labels, DrawOrigin.Y, DrawSize.Height); float[] labels = Y2Scale.CalcYPixels(Y2Labels, DrawOrigin.Y, DrawSize.Height);
float widthMax = 0; float widthMax = 0;
@ -349,7 +371,11 @@ namespace Sunny.UI
g.DrawString(label, TempFont, ForeColor, Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length, y - sf.Height / 2.0f); g.DrawString(label, TempFont, ForeColor, Width - Option.Grid.Right + Option.Y2Axis.AxisTick.Length, y - sf.Height / 2.0f);
} }
if (Option.Y2Axis.AxisTick.Show)
{
g.DrawLine(ForeColor, Width - Option.Grid.Right, y, Width - Option.Grid.Right + Option.YAxis.AxisTick.Length, y); g.DrawLine(ForeColor, Width - Option.Grid.Right, y, Width - Option.Grid.Right + Option.YAxis.AxisTick.Length, y);
}
if (y.Equals(DrawOrigin.Y)) continue; if (y.Equals(DrawOrigin.Y)) continue;
if (y.Equals(DrawOrigin.X - DrawSize.Height)) continue; if (y.Equals(DrawOrigin.X - DrawSize.Height)) continue;

View File

@ -29,6 +29,10 @@ namespace Sunny.UI
{ {
public sealed class UILineOption : UIOption, IDisposable public sealed class UILineOption : UIOption, IDisposable
{ {
public bool ShowZeroLine { get; set; } = true;
public bool ShowZeroValue { get; set; } = false;
public UIAxis XAxis { get; set; } = new UIAxis(UIAxisType.Value); public UIAxis XAxis { get; set; } = new UIAxis(UIAxisType.Value);
public UIAxis YAxis { get; set; } = new UIAxis(UIAxisType.Value); public UIAxis YAxis { get; set; } = new UIAxis(UIAxisType.Value);

View File

@ -94,6 +94,11 @@ namespace Sunny.UI
public int Right { get; set; } = 60; public int Right { get; set; } = 60;
public int Top { get; set; } = 60; public int Top { get; set; } = 60;
public int Bottom { get; set; } = 60; public int Bottom { get; set; } = 60;
public bool LeftShow { get; set; } = true;
public bool RightShow { get; set; } = true;
public bool TopShow { get; set; } = true;
public bool BottomShow { get; set; } = true;
} }
public enum UIOrient public enum UIOrient