diff --git a/Bin/SunnyUI.Demo.exe b/Bin/SunnyUI.Demo.exe index 37d861fe..0f468222 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 4edfd172..ec373534 100644 Binary files a/Bin/SunnyUI.dll and b/Bin/SunnyUI.dll differ diff --git a/Bin/SunnyUI.pdb b/Bin/SunnyUI.pdb index e48cd7b0..7776b9f8 100644 Binary files a/Bin/SunnyUI.pdb and b/Bin/SunnyUI.pdb differ diff --git a/SunnyUI.Demo/Charts/FLineChart.Designer.cs b/SunnyUI.Demo/Charts/FLineChart.Designer.cs index e5d30ffe..20b21c2b 100644 --- a/SunnyUI.Demo/Charts/FLineChart.Designer.cs +++ b/SunnyUI.Demo/Charts/FLineChart.Designer.cs @@ -76,6 +76,7 @@ this.uiImageButton3.TabStop = false; this.uiImageButton3.Text = " Dark"; this.uiImageButton3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.uiImageButton3.Click += new System.EventHandler(this.uiImageButton3_Click); // // uiImageButton2 // @@ -89,6 +90,7 @@ this.uiImageButton2.TabStop = false; this.uiImageButton2.Text = " Plain"; this.uiImageButton2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.uiImageButton2.Click += new System.EventHandler(this.uiImageButton2_Click); // // uiImageButton1 // @@ -102,6 +104,7 @@ this.uiImageButton1.TabStop = false; this.uiImageButton1.Text = " Default"; this.uiImageButton1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.uiImageButton1.Click += new System.EventHandler(this.uiImageButton1_Click); // // uiLine1 // @@ -111,7 +114,7 @@ this.uiLine1.Name = "uiLine1"; this.uiLine1.Size = new System.Drawing.Size(670, 20); this.uiLine1.TabIndex = 30; - this.uiLine1.Text = "UIBarChart"; + this.uiLine1.Text = "UILineChart"; this.uiLine1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // LineChart diff --git a/SunnyUI.Demo/Charts/FLineChart.cs b/SunnyUI.Demo/Charts/FLineChart.cs index 90066bae..8f7ae9f7 100644 --- a/SunnyUI.Demo/Charts/FLineChart.cs +++ b/SunnyUI.Demo/Charts/FLineChart.cs @@ -11,7 +11,7 @@ namespace Sunny.UI.Demo.Charts InitializeComponent(); } - private void uiSymbolButton1_Click(object sender, System.EventArgs e) + private void uiSymbolButton1_Click(object sender, EventArgs e) { UILineOption option = new UILineOption(); option.Title = new UITitle(); @@ -33,7 +33,7 @@ namespace Sunny.UI.Demo.Charts series.SymbolLineWidth = 2; series.SymbolColor = Color.Red; - series = option.AddSeries(new UILineSeries("Line2")); + series = option.AddSeries(new UILineSeries("Line2", Color.Lime)); series.Add(dt.AddHours(0.3), 3.3); series.Add(dt.AddHours(0.4), 2.3); series.Add(dt.AddHours(0.5), 2.3); @@ -51,6 +51,12 @@ namespace Sunny.UI.Demo.Charts // 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.YAxis.Name = "数值"; @@ -68,5 +74,20 @@ namespace Sunny.UI.Demo.Charts Console.WriteLine(sb.ToString()); } + + private void uiImageButton1_Click(object sender, System.EventArgs e) + { + LineChart.ChartStyleType = UIChartStyleType.Default; + } + + private void uiImageButton2_Click(object sender, System.EventArgs e) + { + LineChart.ChartStyleType = UIChartStyleType.Plain; + } + + private void uiImageButton3_Click(object sender, System.EventArgs e) + { + LineChart.ChartStyleType = UIChartStyleType.Dark; + } } } diff --git a/SunnyUI/Charts/UILineChart.cs b/SunnyUI/Charts/UILineChart.cs index 88103548..988f3b00 100644 --- a/SunnyUI/Charts/UILineChart.cs +++ b/SunnyUI/Charts/UILineChart.cs @@ -184,10 +184,10 @@ namespace Sunny.UI // if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow) DrawToolTip(g); DrawAxis(g); DrawTitle(g, LineOption.Title); + DrawAxisScales(g); DrawSeries(g); // if (BarOption.ToolTip != null && BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line) DrawToolTip(g); DrawLegend(g, LineOption.Legend); - DrawAxisScales(g); } private void DrawAxis(Graphics g) @@ -308,16 +308,83 @@ namespace Sunny.UI Color color = series.Color; if (!series.CustomColor) color = ChartStyle.GetColor(idx); - using (Pen pen = new Pen(color, series.Width)) + if (LineOption.GreaterWarningArea == null && LineOption.LessWarningArea == null) { - g.SetHighQuality(); - if (series.Smooth) - g.DrawCurve(pen, series.Points.ToArray()); - else - g.DrawLines(pen, series.Points.ToArray()); - g.SetDefaultQuality(); + 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(); + } } + else + { + Bitmap bmp = new Bitmap(Width, Height); + Bitmap bmpGreater; + Bitmap bmpLess; + float wTop = 0; + float wBottom = Height; + + using (Pen pen = new Pen(color, series.Width)) + { + Graphics graphics = bmp.Graphics(); + graphics.SetHighQuality(); + if (series.Smooth) + graphics.DrawCurve(pen, series.Points.ToArray()); + else + graphics.DrawLines(pen, series.Points.ToArray()); + graphics.SetDefaultQuality(); + } + + if (LineOption.GreaterWarningArea != null) + { + using (Pen pen = new Pen(LineOption.GreaterWarningArea.Color, series.Width)) + using (bmpGreater = new Bitmap(Width, Height)) + { + bmpGreater = new Bitmap(Width, Height); + Graphics graphics = bmpGreater.Graphics(); + graphics.SetHighQuality(); + if (series.Smooth) + graphics.DrawCurve(pen, series.Points.ToArray()); + else + graphics.DrawLines(pen, series.Points.ToArray()); + graphics.SetDefaultQuality(); + + wTop = (float)((LineOption.GreaterWarningArea.Value - YAxisStart * YAxisInterval) * 1.0f * DrawSize.Height / YAxisInterval / (YAxisEnd - YAxisStart)); + wTop = DrawOrigin.Y - wTop; + g.DrawImage(bmpGreater, new Rectangle(0, 0, Width, (int)wTop), + new Rectangle(0, 0, Width, (int)wTop), GraphicsUnit.Pixel); + } + } + + if (LineOption.LessWarningArea != null) + { + using (Pen pen = new Pen(LineOption.LessWarningArea.Color, series.Width)) + using (bmpLess = new Bitmap(Width, Height)) + { + Graphics graphics = bmpLess.Graphics(); + graphics.SetHighQuality(); + if (series.Smooth) + graphics.DrawCurve(pen, series.Points.ToArray()); + else + graphics.DrawLines(pen, series.Points.ToArray()); + graphics.SetDefaultQuality(); + + wBottom = (float)((LineOption.LessWarningArea.Value - YAxisStart * YAxisInterval) * 1.0f * DrawSize.Height / YAxisInterval / (YAxisEnd - YAxisStart)); + wBottom = DrawOrigin.Y - wBottom; + g.DrawImage(bmpLess, new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom), + new Rectangle(0, (int)wBottom, Width, Height - (int)wBottom), GraphicsUnit.Pixel); + } + } + + g.DrawImage(bmp, new Rectangle(0, (int)wTop, Width, (int)wBottom - (int)wTop), + new Rectangle(0, (int)wTop, Width, (int)wBottom - (int)wTop), GraphicsUnit.Pixel); + bmp.Dispose(); + } if (series.Symbol != UILinePointSymbol.None) { diff --git a/SunnyUI/Charts/UILineChartOption.cs b/SunnyUI/Charts/UILineChartOption.cs index 4b80d5c5..7cf67929 100644 --- a/SunnyUI/Charts/UILineChartOption.cs +++ b/SunnyUI/Charts/UILineChartOption.cs @@ -30,6 +30,9 @@ namespace Sunny.UI public readonly List YAxisScaleLines = new List(); + public UILineWarningArea GreaterWarningArea { get; set; } + public UILineWarningArea LessWarningArea { get; set; } + public UILineSeries AddSeries(UILineSeries series) { if (series.Name.IsNullOrEmpty()) return null; @@ -278,4 +281,27 @@ namespace Sunny.UI public double Y { get; set; } } + + public class UILineWarningArea + { + public double Value { get; set; } + + public Color Color { get; set; } = Color.Red; + + public UILineWarningArea() + { + + } + + public UILineWarningArea(double value) + { + Value = value; + } + + public UILineWarningArea(double value, Color color) + { + Value = value; + Color = color; + } + } }