* UIBarChart: 数据显示的小数位数重构调整至数据序列Series.DecimalPlaces

This commit is contained in:
Sunny 2022-07-29 11:44:46 +08:00
parent 2cc9ef5308
commit 495328c1e5
2 changed files with 37 additions and 20 deletions

View File

@ -22,6 +22,7 @@
* 2021-01-01: V3.0.9 * 2021-01-01: V3.0.9
* 2022-03-08: V3.1.1 X轴文字倾斜 * 2022-03-08: V3.1.1 X轴文字倾斜
* 2022-05-27: V3.1.9 Y轴坐标显示 * 2022-05-27: V3.1.9 Y轴坐标显示
* 2022-07-29: V3.2.2 Series.DecimalPlaces
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -194,7 +195,8 @@ namespace Sunny.UI
Rect = new RectangleF(xx, VPos, ww, (YZeroPos - VPos)), Rect = new RectangleF(xx, VPos, ww, (YZeroPos - VPos)),
Value = series.Data[j], Value = series.Data[j],
Color = color, Color = color,
Top = true Top = true,
Series = series,
}); });
} }
else else
@ -204,7 +206,8 @@ namespace Sunny.UI
Rect = new RectangleF(xx, YZeroPos, ww, (VPos - YZeroPos)), Rect = new RectangleF(xx, YZeroPos, ww, (VPos - YZeroPos)),
Value = series.Data[j], Value = series.Data[j],
Color = color, Color = color,
Top = false Top = false,
Series = series,
}); });
} }
@ -220,7 +223,7 @@ namespace Sunny.UI
foreach (var series in Option.Series) foreach (var series in Option.Series)
{ {
str += '\n'; str += '\n';
//str += series.Name + " : " + series.Data[i].ToString(Option.ToolTip.ValueFormat); str += series.Name + " : " + series.Data[i].ToString("F" + series.DecimalPlaces);
} }
Bars[0][i].Tips = str; Bars[0][i].Tips = str;
@ -527,23 +530,23 @@ namespace Sunny.UI
if (Option.ShowValue) if (Option.ShowValue)
{ {
//string value = info.Value.ToString(Option.ToolTip.ValueFormat); string value = info.Value.ToString("F" + info.Series.DecimalPlaces);
//SizeF sf = g.MeasureString(value, TempFont); SizeF sf = g.MeasureString(value, TempFont);
//if (info.Top) if (info.Top)
//{ {
// float top = info.Rect.Top - sf.Height; float top = info.Rect.Top - sf.Height;
// if (top > Option.Grid.Top) if (top > Option.Grid.Top)
// { {
// g.DrawString(value, TempFont, info.Color, info.Rect.Center().X - sf.Width / 2, top); g.DrawString(value, TempFont, info.Color, info.Rect.Center().X - sf.Width / 2, top);
// } }
//} }
//else else
//{ {
// if (info.Rect.Bottom + sf.Height + Option.Grid.Bottom < Height) 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); g.DrawString(value, TempFont, info.Color, info.Rect.Center().X - sf.Width / 2, info.Rect.Bottom);
// } }
//} }
} }
} }
} }
@ -568,6 +571,8 @@ namespace Sunny.UI
public double Value { get; set; } public double Value { get; set; }
public bool Top { get; set; } public bool Top { get; set; }
public UIBarSeries Series { get; set; }
} }
} }
} }

View File

@ -411,6 +411,11 @@ namespace Sunny.UI
public class UIBarSeries : IDisposable public class UIBarSeries : IDisposable
{ {
public UIBarSeries(int decimalPlaces = 0)
{
DecimalPlaces = decimalPlaces;
}
public string Name { get; set; } public string Name { get; set; }
public int MaxWidth { get; set; } = int.MaxValue; public int MaxWidth { get; set; } = int.MaxValue;
@ -423,6 +428,13 @@ namespace Sunny.UI
public readonly List<Color> Colors = new List<Color>(); public readonly List<Color> Colors = new List<Color>();
private int _decimalPlaces = 0;
public int DecimalPlaces
{
get => _decimalPlaces;
set => _decimalPlaces = Math.Max(0, value);
}
public bool ShowBarName { get; set; } public bool ShowBarName { get; set; }
public bool ShowValue { get; set; } public bool ShowValue { get; set; }