From 5f97773d583ab9ec65a45747762644ceadee1a93 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 25 Jul 2023 23:14:28 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIChart:=20Legend=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E7=A7=8D=E7=BB=98=E5=88=B6=E7=9B=B4=E7=BA=BF=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Charts/UIChart.cs | 13 +++++++++++-- SunnyUI/Charts/UIOption.cs | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/SunnyUI/Charts/UIChart.cs b/SunnyUI/Charts/UIChart.cs index fcb96c0b..cbc80383 100644 --- a/SunnyUI/Charts/UIChart.cs +++ b/SunnyUI/Charts/UIChart.cs @@ -19,6 +19,7 @@ * 2020-06-06: V2.2.5 增加文件说明 * 2020-09-10: V2.2.7 增加图表的边框线颜色设置 * 2023-05-14: V3.3.6 重构DrawString函数 + * 2023-07-25: V3.4.1 Legend增加一种绘制直线的方法 ******************************************************************************/ using System; @@ -331,7 +332,11 @@ namespace Sunny.UI if (legend.Orient == UIOrient.Horizontal) { - g.FillRoundRectangle(color, (int)startLeft, (int)top + 1, 18, (int)oneHeight - 2, 5); + if (legend.Style == UILegendStyle.Rectangle) + g.FillRoundRectangle(color, (int)startLeft, (int)top + 1, 18, (int)oneHeight - 2, 5); + if (legend.Style == UILegendStyle.Line) + g.DrawLine(color, startLeft, top + oneHeight / 2, startLeft + 18, top + oneHeight / 2); + g.DrawString(data, TempLegendFont, color, new Rectangle((int)startLeft + 18, (int)top, Width, Height), ContentAlignment.TopLeft); startLeft += 22; startLeft += sf.Width; @@ -339,7 +344,11 @@ namespace Sunny.UI if (legend.Orient == UIOrient.Vertical) { - g.FillRoundRectangle(color, (int)left, (int)startTop + 1, 18, (int)oneHeight - 2, 5); + if (legend.Style == UILegendStyle.Rectangle) + g.FillRoundRectangle(color, (int)left, (int)startTop + 1, 18, (int)oneHeight - 2, 5); + if (legend.Style == UILegendStyle.Line) + g.DrawLine(color, left, startTop, left + 18, startTop + oneHeight / 2); + g.DrawString(data, TempLegendFont, color, new Rectangle((int)left + 18, (int)startTop, Width, Height), ContentAlignment.TopLeft); startTop += oneHeight; } diff --git a/SunnyUI/Charts/UIOption.cs b/SunnyUI/Charts/UIOption.cs index 87ce4b83..2baf4af6 100644 --- a/SunnyUI/Charts/UIOption.cs +++ b/SunnyUI/Charts/UIOption.cs @@ -327,6 +327,8 @@ namespace Sunny.UI public int DataCount => Data.Count; + public UILegendStyle Style { get; set; } = UILegendStyle.Rectangle; + public void AddData(string data) { Data.Add(data); @@ -350,6 +352,12 @@ namespace Sunny.UI } } + public enum UILegendStyle + { + Rectangle, + Line + } + public class UIChartGrid { public int Left { get; set; } = 60;