* UIBarChart: Option.BarInterval,设置Bar之间间隔,默认-1,自动计算间隔

This commit is contained in:
Sunny 2023-05-12 16:27:05 +08:00
parent 26255f9169
commit e74a9891d2
2 changed files with 90 additions and 38 deletions

View File

@ -28,6 +28,7 @@
* 2022-08-17: V3.2.3 Nan * 2022-08-17: V3.2.3 Nan
* 2022-09-07: V3.2.3 Option.YAxis.ShowGridLine为false时线 * 2022-09-07: V3.2.3 Option.YAxis.ShowGridLine为false时线
* 2022-05-10: V3.3.6 Option.ShowFullRect为true时线 * 2022-05-10: V3.3.6 Option.ShowFullRect为true时线
* 2022-05-13: V3.3.6 Option.BarInterval,Bar之间间隔-1
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -184,6 +185,8 @@ namespace Sunny.UI
float x1 = DrawBarWidth / (Option.SeriesCount * 2 + Option.SeriesCount + 1); float x1 = DrawBarWidth / (Option.SeriesCount * 2 + Option.SeriesCount + 1);
float x2 = x1 * 2; float x2 = x1 * 2;
if (Option.BarInterval < 0 || Option.BarInterval > x1 || Option.SeriesCount == 1)
{
for (int i = 0; i < Option.SeriesCount; i++) for (int i = 0; i < Option.SeriesCount; i++)
{ {
float barX = DrawOrigin.X; float barX = DrawOrigin.X;
@ -228,6 +231,53 @@ namespace Sunny.UI
barX += DrawBarWidth; barX += DrawBarWidth;
} }
} }
}
else
{
for (int i = 0; i < Option.SeriesCount; i++)
{
float barX = DrawOrigin.X;
var series = Option.Series[i];
Bars.TryAdd(i, new List<BarInfo>());
for (int j = 0; j < series.Data.Count; j++)
{
Color color = ChartStyle.GetColor(i);
if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
color = series.Colors[j];
float ww = Math.Min(x2, series.MaxWidth);
float xl = (DrawBarWidth - Option.SeriesCount * ww - (Option.SeriesCount - 1) * Option.BarInterval) / 2.0f;
float xx = barX + xl + i * ww + i * Option.BarInterval;
float YZeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height);
float VPos = YScale.CalcYPixel(series.Data[j], DrawOrigin.Y, DrawSize.Height);
if (VPos <= YZeroPos)
{
Bars[i].Add(new BarInfo()
{
Rect = new RectangleF(xx, VPos, ww, (YZeroPos - VPos)),
Value = series.Data[j],
Color = color,
Top = true,
Series = series,
});
}
else
{
Bars[i].Add(new BarInfo()
{
Rect = new RectangleF(xx, YZeroPos, ww, (VPos - YZeroPos)),
Value = series.Data[j],
Color = color,
Top = false,
Series = series,
});
}
barX += DrawBarWidth;
}
}
}
if (Option.ToolTip != null) if (Option.ToolTip != null)
{ {

View File

@ -85,6 +85,8 @@ namespace Sunny.UI
public float AutoSizeBarsCompactValue { get; set; } = 1.0f; public float AutoSizeBarsCompactValue { get; set; } = 1.0f;
public int BarInterval { get; set; } = -1;
public void AddSeries(UIBarSeries series) public void AddSeries(UIBarSeries series)
{ {
if (series == null) if (series == null)