diff --git a/SunnyUI/Charts/UIBarChart.cs b/SunnyUI/Charts/UIBarChart.cs index 152ca36f..1df45e65 100644 --- a/SunnyUI/Charts/UIBarChart.cs +++ b/SunnyUI/Charts/UIBarChart.cs @@ -220,7 +220,7 @@ namespace Sunny.UI foreach (var series in Option.Series) { str += '\n'; - str += series.Name + " : " + series.Data[i].ToString(Option.ToolTip.ValueFormat); + //str += series.Name + " : " + series.Data[i].ToString(Option.ToolTip.ValueFormat); } Bars[0][i].Tips = str; @@ -527,23 +527,23 @@ namespace Sunny.UI if (Option.ShowValue) { - string value = info.Value.ToString(Option.ToolTip.ValueFormat); - SizeF sf = g.MeasureString(value, TempFont); - if (info.Top) - { - float top = info.Rect.Top - sf.Height; - if (top > Option.Grid.Top) - { - g.DrawString(value, TempFont, info.Color, info.Rect.Center().X - sf.Width / 2, top); - } - } - else - { - if (info.Rect.Bottom + sf.Height + Option.Grid.Bottom < Height) - { - g.DrawString(value, TempFont, info.Color, info.Rect.Center().X - sf.Width / 2, info.Rect.Bottom); - } - } + //string value = info.Value.ToString(Option.ToolTip.ValueFormat); + //SizeF sf = g.MeasureString(value, TempFont); + //if (info.Top) + //{ + // float top = info.Rect.Top - sf.Height; + // if (top > Option.Grid.Top) + // { + // g.DrawString(value, TempFont, info.Color, info.Rect.Center().X - sf.Width / 2, top); + // } + //} + //else + //{ + // if (info.Rect.Bottom + sf.Height + Option.Grid.Bottom < Height) + // { + // g.DrawString(value, TempFont, info.Color, info.Rect.Center().X - sf.Width / 2, info.Rect.Bottom); + // } + //} } } } diff --git a/SunnyUI/Charts/UIBarChartOption.cs b/SunnyUI/Charts/UIBarChartOption.cs index 9a581d8c..d5c95646 100644 --- a/SunnyUI/Charts/UIBarChartOption.cs +++ b/SunnyUI/Charts/UIBarChartOption.cs @@ -125,7 +125,6 @@ namespace Sunny.UI public UIBarToolTip() { Formatter = "{{b}} : {{c}}"; - ValueFormat = "F0"; } } diff --git a/SunnyUI/Charts/UIDoughnutChart.cs b/SunnyUI/Charts/UIDoughnutChart.cs index 4df5d4be..8014cf51 100644 --- a/SunnyUI/Charts/UIDoughnutChart.cs +++ b/SunnyUI/Charts/UIDoughnutChart.cs @@ -18,6 +18,7 @@ * * 2020-06-06: V2.2.5 增加文件说明 * 2021-07-22: V3.0.5 增加更新数据的方法 + * 2022-07-29: V3.2.2 数据显示的小数位数重构调整至Option.DecimalPlaces ******************************************************************************/ using System; @@ -134,7 +135,7 @@ namespace Sunny.UI UITemplate template = new UITemplate(Option.ToolTip.Formatter); template.Set("a", pie.Name); template.Set("b", pie.Data[i].Name); - template.Set("c", pie.Data[i].Value.ToString(Option.ToolTip.ValueFormat)); + template.Set("c", pie.Data[i].Value.ToString("F" + Option.DecimalPlaces)); template.Set("d", percent.ToString("F2")); text = template.Render(); } diff --git a/SunnyUI/Charts/UIOption.cs b/SunnyUI/Charts/UIOption.cs index f7233531..9b11424d 100644 --- a/SunnyUI/Charts/UIOption.cs +++ b/SunnyUI/Charts/UIOption.cs @@ -36,8 +36,6 @@ namespace Sunny.UI public bool Visible { get; set; } public string Formatter { get; set; } - - public string ValueFormat { get; set; } } public class UIScaleLine diff --git a/SunnyUI/Charts/UIPieChart.cs b/SunnyUI/Charts/UIPieChart.cs index 2cf6fea8..7ab0d0d2 100644 --- a/SunnyUI/Charts/UIPieChart.cs +++ b/SunnyUI/Charts/UIPieChart.cs @@ -18,6 +18,7 @@ * * 2020-06-06: V2.2.5 增加文件说明 * 2021-07-22: V3.0.5 增加更新数据的方法 + * 2022-07-29: V3.2.2 数据显示的小数位数重构调整至Option.DecimalPlaces ******************************************************************************/ using System; @@ -136,13 +137,13 @@ namespace Sunny.UI UITemplate template = new UITemplate(Option.ToolTip.Formatter); template.Set("a", pie.Name); template.Set("b", pie.Data[i].Name); - template.Set("c", pie.Data[i].Value.ToString(Option.ToolTip.ValueFormat)); + template.Set("c", pie.Data[i].Value.ToString("F" + Option.DecimalPlaces)); template.Set("d", percent.ToString("F2")); text = template.Render(); } catch { - text = pie.Data[i].Name + " : " + pie.Data[i].Value.ToString("F2") + "(" + percent.ToString("F2") + "%)"; + text = pie.Data[i].Name + " : " + pie.Data[i].Value.ToString("F" + Option.DecimalPlaces) + "(" + percent.ToString("F2") + "%)"; if (pie.Name.IsValid()) text = pie.Name + '\n' + text; } } @@ -191,7 +192,7 @@ namespace Sunny.UI string name = Option.Legend != null ? Option.Legend.Data[azIndex] + " : " : ""; if (pie.Data[azIndex].Value > 0) { - string text = name + pie.Data[azIndex].Value.ToString("F0"); + string text = name + pie.Data[azIndex].Value.ToString("F" + Option.DecimalPlaces); SizeF sf = g.MeasureString(text, TempFont); PointF pf; int added = 9; diff --git a/SunnyUI/Charts/UIPieChartOption.cs b/SunnyUI/Charts/UIPieChartOption.cs index 1d7eeea5..f5281833 100644 --- a/SunnyUI/Charts/UIPieChartOption.cs +++ b/SunnyUI/Charts/UIPieChartOption.cs @@ -64,6 +64,13 @@ namespace Sunny.UI return null; } } + + private int decimalPlaces = 0; + public int DecimalPlaces + { + get => decimalPlaces; + set => decimalPlaces = Math.Max(0, value); + } } public class UIDoughnutOption : UIOption, IDisposable @@ -105,6 +112,13 @@ namespace Sunny.UI return null; } } + + private int decimalPlaces = 0; + public int DecimalPlaces + { + get => decimalPlaces; + set => decimalPlaces = Math.Max(0, value); + } } public class UIPieToolTip : UIChartToolTip @@ -112,7 +126,6 @@ namespace Sunny.UI public UIPieToolTip() { Formatter = "{{a}}" + '\n' + "{{b}} : {{c}} ({{d}}%)"; - ValueFormat = "F0"; Visible = true; } }