* UIBarChart:可设置柱状图最小宽度

This commit is contained in:
Sunny 2020-08-21 23:59:15 +08:00
parent c989dbf925
commit 169be3c9e3
6 changed files with 10 additions and 17 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -79,23 +79,23 @@ namespace Sunny.UI
float barX = DrawOrigin.X; float barX = DrawOrigin.X;
var series = o.Series[i]; var series = o.Series[i];
Bars.TryAdd(i, new List<BarInfo>()); Bars.TryAdd(i, new List<BarInfo>());
for (int j = 0; j < series.Data.Count; j++) for (int j = 0; j < series.Data.Count; j++)
{ {
Color color = ChartStyle.GetColor(i); Color color = ChartStyle.GetColor(i);
if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count) if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
color = series.Colors[j]; color = series.Colors[j];
float xx = barX + x1 * (i + 1) + x2 * i + x1;
float ww = Math.Min(x2, series.MaxWidth);
xx = xx - ww / 2.0f;
if (YAxisStart >= 0) if (YAxisStart >= 0)
{ {
float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval))); float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));
Bars[i].Add(new BarInfo() Bars[i].Add(new BarInfo()
{ {
Rect = new RectangleF( Rect = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
barX + x1 * (i + 1) + x2 * i,
DrawOrigin.Y - h,
x2, h),
Color = color Color = color
}); });
} }
@ -104,10 +104,7 @@ namespace Sunny.UI
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval))); float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
Bars[i].Add(new BarInfo() Bars[i].Add(new BarInfo()
{ {
Rect = new RectangleF( Rect = new RectangleF(xx, BarOption.Grid.Top + 1, ww, h - 1),
barX + x1 * (i + 1) + x2 * i,
BarOption.Grid.Top + 1,
x2, h - 1),
Color = color Color = color
}); });
} }
@ -134,10 +131,7 @@ namespace Sunny.UI
float h = Math.Abs((float)(highH * series.Data[j] / highV)); float h = Math.Abs((float)(highH * series.Data[j] / highV));
Bars[i].Add(new BarInfo() Bars[i].Add(new BarInfo()
{ {
Rect = new RectangleF( Rect = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
barX + x1 * (i + 1) + x2 * i,
DrawOrigin.Y - lowH - h,
x2, h),
Color = color Color = color
}); });
} }
@ -146,10 +140,7 @@ namespace Sunny.UI
float h = Math.Abs((float)(lowH * series.Data[j] / lowV)); float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
Bars[i].Add(new BarInfo() Bars[i].Add(new BarInfo()
{ {
Rect = new RectangleF( Rect = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
barX + x1 * (i + 1) + x2 * i,
DrawOrigin.Y - lowH + 1,
x2, h - 1),
Color = color Color = color
}); });
} }

View File

@ -170,6 +170,8 @@ namespace Sunny.UI
{ {
public string Name { get; set; } public string Name { get; set; }
public int MaxWidth { get; set; } = int.MaxValue;
public UISeriesType Type => UISeriesType.Bar; public UISeriesType Type => UISeriesType.Bar;
public readonly List<double> Data = new List<double>(); public readonly List<double> Data = new List<double>();