* UIBarChartEx:更新
This commit is contained in:
parent
942a596aec
commit
7fd450f609
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
BIN
Bin/SunnyUI.pdb
BIN
Bin/SunnyUI.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -82,10 +82,12 @@ namespace Sunny.UI.Demo
|
|||||||
option.XAxis.AxisTick.Distance = 14;
|
option.XAxis.AxisTick.Distance = 14;
|
||||||
|
|
||||||
option.FixedSeriesCount = 3;
|
option.FixedSeriesCount = 3;
|
||||||
|
option.AutoSizeBars = true;
|
||||||
|
|
||||||
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 12 });
|
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 12 });
|
||||||
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = -20 });
|
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = -20 });
|
||||||
|
|
||||||
|
option.ToolTip.AxisPointer.Type = UIAxisPointerType.Shadow;
|
||||||
BarChart.SetOption(option);
|
BarChart.SetOption(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ namespace Sunny.UI
|
|||||||
DrawAxisScales(g);
|
DrawAxisScales(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawToolTip(Graphics g)
|
protected virtual void DrawToolTip(Graphics g)
|
||||||
{
|
{
|
||||||
if (selectIndex < 0) return;
|
if (selectIndex < 0) return;
|
||||||
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line)
|
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line)
|
||||||
|
@ -61,92 +61,170 @@ namespace Sunny.UI
|
|||||||
YAxisInterval = interval;
|
YAxisInterval = interval;
|
||||||
float barX = DrawOrigin.X;
|
float barX = DrawOrigin.X;
|
||||||
|
|
||||||
for (int i = 0; i < o.SeriesCount; i++)
|
if (BarOption.AutoSizeBars)
|
||||||
{
|
{
|
||||||
var series = o.Series[i];
|
float x1 = DrawSize.Width * 1.0f / DataCount / 4;
|
||||||
float x1;
|
|
||||||
if (BarOption.FixedSeriesCount > 0)
|
|
||||||
x1 = DrawBarWidth / (BarOption.FixedSeriesCount * 2 + BarOption.FixedSeriesCount + 1);
|
|
||||||
else
|
|
||||||
x1 = DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1);
|
|
||||||
|
|
||||||
float x2 = x1 * 2;
|
float x2 = x1 * 2;
|
||||||
|
|
||||||
Bars.TryAdd(i, new List<BarInfo>());
|
for (int i = 0; i < o.SeriesCount; i++)
|
||||||
for (int j = 0; j < series.Data.Count; j++)
|
|
||||||
{
|
{
|
||||||
Color color = ChartStyle.GetColor(i);
|
var series = o.Series[i];
|
||||||
if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
|
Bars.TryAdd(i, new List<BarInfo>());
|
||||||
color = series.Colors[j];
|
|
||||||
|
|
||||||
float xx;
|
for (int j = 0; j < series.Data.Count; j++)
|
||||||
if (BarOption.FixedSeriesCount > 0)
|
|
||||||
xx = barX + DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1) * ((j + 1) * 3 - 1);
|
|
||||||
else
|
|
||||||
xx = barX + x1 * ((j + 1) * 3 - 1);
|
|
||||||
|
|
||||||
float ww = Math.Min(x2, series.MaxWidth);
|
|
||||||
xx = xx - ww / 2.0f;
|
|
||||||
|
|
||||||
if (YAxisStart >= 0)
|
|
||||||
{
|
{
|
||||||
float h = Math.Abs((float)(DrawSize.Height * (series.Data[j] - start * interval) / ((end - start) * interval)));
|
Color color = ChartStyle.GetColor(i);
|
||||||
|
if (series.Colors.Count > 0 && j >= 0 && j < series.Colors.Count)
|
||||||
|
color = series.Colors[j];
|
||||||
|
|
||||||
Bars[i].Add(new BarInfo()
|
float xx = barX + DrawSize.Width * 1.0f / DataCount / 2;
|
||||||
{
|
float ww = Math.Min(x2, series.MaxWidth);
|
||||||
Rect = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
|
xx = xx - ww / 2.0f;
|
||||||
Color = color
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (YAxisEnd <= 0)
|
|
||||||
{
|
|
||||||
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
|
|
||||||
Bars[i].Add(new BarInfo()
|
|
||||||
{
|
|
||||||
Rect = new RectangleF(xx, BarOption.Grid.Top + 1, ww, h - 1),
|
|
||||||
Color = color
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float lowH = 0;
|
|
||||||
float highH = 0;
|
|
||||||
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
|
|
||||||
float lowV = 0;
|
|
||||||
float highV = 0;
|
|
||||||
for (int k = YAxisStart; k <= YAxisEnd; k++)
|
|
||||||
{
|
|
||||||
if (k < 0) lowH += DrawBarHeight;
|
|
||||||
if (k > 0) highH += DrawBarHeight;
|
|
||||||
if (k < 0) lowV += (float)YAxisInterval;
|
|
||||||
if (k > 0) highV += (float)YAxisInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
// lowH.ConsoleWriteLine();
|
if (YAxisStart >= 0)
|
||||||
// highH.ConsoleWriteLine();
|
|
||||||
|
|
||||||
if (series.Data[j] >= 0)
|
|
||||||
{
|
{
|
||||||
float h = Math.Abs((float)(highH * series.Data[j] / highV));
|
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(xx, DrawOrigin.Y - lowH - h, ww, h),
|
Rect = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
|
||||||
|
Color = color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (YAxisEnd <= 0)
|
||||||
|
{
|
||||||
|
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
|
||||||
|
Bars[i].Add(new BarInfo()
|
||||||
|
{
|
||||||
|
Rect = new RectangleF(xx, BarOption.Grid.Top + 1, ww, h - 1),
|
||||||
Color = color
|
Color = color
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
|
float lowH = 0;
|
||||||
|
float highH = 0;
|
||||||
|
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
|
||||||
|
float lowV = 0;
|
||||||
|
float highV = 0;
|
||||||
|
for (int k = YAxisStart; k <= YAxisEnd; k++)
|
||||||
|
{
|
||||||
|
if (k < 0) lowH += DrawBarHeight;
|
||||||
|
if (k > 0) highH += DrawBarHeight;
|
||||||
|
if (k < 0) lowV += (float)YAxisInterval;
|
||||||
|
if (k > 0) highV += (float)YAxisInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (series.Data[j] >= 0)
|
||||||
|
{
|
||||||
|
float h = Math.Abs((float)(highH * series.Data[j] / highV));
|
||||||
|
Bars[i].Add(new BarInfo()
|
||||||
|
{
|
||||||
|
Rect = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
|
||||||
|
Color = color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
|
||||||
|
Bars[i].Add(new BarInfo()
|
||||||
|
{
|
||||||
|
Rect = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
|
||||||
|
Color = color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
barX += DrawSize.Width * 1.0f / DataCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < o.SeriesCount; i++)
|
||||||
|
{
|
||||||
|
var series = o.Series[i];
|
||||||
|
float x1;
|
||||||
|
if (BarOption.FixedSeriesCount > 0)
|
||||||
|
x1 = DrawBarWidth / (BarOption.FixedSeriesCount * 2 + BarOption.FixedSeriesCount + 1);
|
||||||
|
else
|
||||||
|
x1 = DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1);
|
||||||
|
|
||||||
|
float x2 = x1 * 2;
|
||||||
|
|
||||||
|
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 xx;
|
||||||
|
if (BarOption.FixedSeriesCount > 0)
|
||||||
|
xx = barX + DrawBarWidth / (series.Data.Count * 2 + series.Data.Count + 1) * ((j + 1) * 3 - 1);
|
||||||
|
else
|
||||||
|
xx = barX + x1 * ((j + 1) * 3 - 1);
|
||||||
|
|
||||||
|
float ww = Math.Min(x2, series.MaxWidth);
|
||||||
|
xx = xx - ww / 2.0f;
|
||||||
|
|
||||||
|
if (YAxisStart >= 0)
|
||||||
|
{
|
||||||
|
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(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
|
Rect = new RectangleF(xx, DrawOrigin.Y - h, ww, h),
|
||||||
Color = color
|
Color = color
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
else if (YAxisEnd <= 0)
|
||||||
}
|
{
|
||||||
|
float h = Math.Abs((float)(DrawSize.Height * (end * interval - series.Data[j]) / ((end - start) * interval)));
|
||||||
|
Bars[i].Add(new BarInfo()
|
||||||
|
{
|
||||||
|
Rect = new RectangleF(xx, BarOption.Grid.Top + 1, ww, h - 1),
|
||||||
|
Color = color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float lowH = 0;
|
||||||
|
float highH = 0;
|
||||||
|
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
|
||||||
|
float lowV = 0;
|
||||||
|
float highV = 0;
|
||||||
|
for (int k = YAxisStart; k <= YAxisEnd; k++)
|
||||||
|
{
|
||||||
|
if (k < 0) lowH += DrawBarHeight;
|
||||||
|
if (k > 0) highH += DrawBarHeight;
|
||||||
|
if (k < 0) lowV += (float)YAxisInterval;
|
||||||
|
if (k > 0) highV += (float)YAxisInterval;
|
||||||
|
}
|
||||||
|
|
||||||
barX += DrawBarWidth;
|
if (series.Data[j] >= 0)
|
||||||
|
{
|
||||||
|
float h = Math.Abs((float)(highH * series.Data[j] / highV));
|
||||||
|
Bars[i].Add(new BarInfo()
|
||||||
|
{
|
||||||
|
Rect = new RectangleF(xx, DrawOrigin.Y - lowH - h, ww, h),
|
||||||
|
Color = color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float h = Math.Abs((float)(lowH * series.Data[j] / lowV));
|
||||||
|
Bars[i].Add(new BarInfo()
|
||||||
|
{
|
||||||
|
Rect = new RectangleF(xx, DrawOrigin.Y - lowH + 1, ww, h - 1),
|
||||||
|
Color = color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
barX += DrawBarWidth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BarOption.ToolTip != null)
|
if (BarOption.ToolTip != null)
|
||||||
@ -218,6 +296,20 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int DataCount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int dataCount = 0;
|
||||||
|
for (int i = 0; i < BarOption.SeriesCount; i++)
|
||||||
|
{
|
||||||
|
dataCount += BarOption.Series[i].Data.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void DrawAxis(Graphics g)
|
protected override void DrawAxis(Graphics g)
|
||||||
{
|
{
|
||||||
if (YAxisStart >= 0) g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
|
if (YAxisStart >= 0) g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
|
||||||
@ -225,34 +317,50 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X, DrawOrigin.Y - DrawSize.Height));
|
g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X, DrawOrigin.Y - DrawSize.Height));
|
||||||
|
|
||||||
|
//绘制X轴刻度
|
||||||
if (BarOption.XAxis.AxisTick.Show)
|
if (BarOption.XAxis.AxisTick.Show)
|
||||||
{
|
{
|
||||||
float start;
|
float start;
|
||||||
|
|
||||||
if (BarOption.XAxis.AxisTick.AlignWithLabel)
|
if (BarOption.XAxis.AxisTick.AlignWithLabel)
|
||||||
{
|
{
|
||||||
start = DrawOrigin.X + DrawBarWidth / 2.0f;
|
if (BarOption.AutoSizeBars)
|
||||||
for (int i = 0; i < BarOption.Series.Count; i++)
|
|
||||||
{
|
{
|
||||||
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
|
start = DrawOrigin.X;
|
||||||
start += DrawBarWidth;
|
for (int i = 0; i < BarOption.Series.Count; i++)
|
||||||
|
{
|
||||||
|
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
|
||||||
|
g.DrawLine(ChartStyle.ForeColor, start + (int)(w / 2), DrawOrigin.Y, start + (int)(w / 2), DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
|
||||||
|
start += (int)w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start = DrawOrigin.X + DrawBarWidth / 2.0f;
|
||||||
|
for (int i = 0; i < BarOption.Series.Count; i++)
|
||||||
|
{
|
||||||
|
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
|
||||||
|
start += DrawBarWidth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool haveZero = false;
|
start = DrawOrigin.X;
|
||||||
for (int i = YAxisStart; i <= YAxisEnd; i++)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
haveZero = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!haveZero)
|
if (BarOption.AutoSizeBars)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < BarOption.Series.Count; i++)
|
||||||
|
{
|
||||||
|
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
|
||||||
|
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
|
||||||
|
start += (int)w;
|
||||||
|
}
|
||||||
|
|
||||||
|
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X + DrawSize.Width, DrawOrigin.Y, DrawOrigin.X + DrawSize.Width, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
start = DrawOrigin.X;
|
|
||||||
for (int i = 0; i <= BarOption.Series.Count; i++)
|
for (int i = 0; i <= BarOption.Series.Count; i++)
|
||||||
{
|
{
|
||||||
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
|
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length);
|
||||||
@ -262,20 +370,36 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//绘制X轴标签
|
||||||
if (BarOption.XAxis.AxisLabel.Show)
|
if (BarOption.XAxis.AxisLabel.Show)
|
||||||
{
|
{
|
||||||
float start = DrawOrigin.X + DrawBarWidth / 2.0f;
|
if (BarOption.AutoSizeBars)
|
||||||
foreach (var data in BarOption.Series)
|
|
||||||
{
|
{
|
||||||
SizeF sf = g.MeasureString(data.Name, SubFont);
|
float start = DrawOrigin.X;
|
||||||
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance);
|
foreach (var data in BarOption.Series)
|
||||||
start += DrawBarWidth;
|
{
|
||||||
|
float w = DrawSize.Width * data.Data.Count * 1.0f / DataCount;
|
||||||
|
SizeF sf = g.MeasureString(data.Name, SubFont);
|
||||||
|
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance);
|
||||||
|
start += w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float start = DrawOrigin.X + DrawBarWidth / 2.0f;
|
||||||
|
foreach (var data in BarOption.Series)
|
||||||
|
{
|
||||||
|
SizeF sf = g.MeasureString(data.Name, SubFont);
|
||||||
|
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance);
|
||||||
|
start += DrawBarWidth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SizeF sfName = g.MeasureString(BarOption.XAxis.Name, SubFont);
|
SizeF sfName = g.MeasureString(BarOption.XAxis.Name, SubFont);
|
||||||
g.DrawString(BarOption.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance + sfName.Height);
|
g.DrawString(BarOption.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + BarOption.XAxis.AxisTick.Length + BarOption.XAxis.AxisTick.Distance + sfName.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//绘制Y轴刻度
|
||||||
if (BarOption.YAxis.AxisTick.Show)
|
if (BarOption.YAxis.AxisTick.Show)
|
||||||
{
|
{
|
||||||
float start = DrawOrigin.Y;
|
float start = DrawOrigin.Y;
|
||||||
@ -298,17 +422,18 @@ namespace Sunny.UI
|
|||||||
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, Width - BarOption.Grid.Right, start);
|
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, Width - BarOption.Grid.Right, start);
|
||||||
|
|
||||||
float lineStart = DrawOrigin.X;
|
float lineStart = DrawOrigin.X;
|
||||||
for (int j = 0; j <= BarOption.Series.Count; j++)
|
// for (int j = 0; j <= BarOption.Series.Count; j++)
|
||||||
{
|
// {
|
||||||
g.DrawLine(ChartStyle.ForeColor, lineStart, start, lineStart, start + BarOption.XAxis.AxisTick.Length);
|
// g.DrawLine(ChartStyle.ForeColor, lineStart, start, lineStart, start + BarOption.XAxis.AxisTick.Length);
|
||||||
lineStart += DrawBarWidth;
|
// lineStart += DrawBarWidth;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
start -= DrawBarHeight;
|
start -= DrawBarHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//绘制Y轴标签
|
||||||
if (BarOption.YAxis.AxisLabel.Show)
|
if (BarOption.YAxis.AxisLabel.Show)
|
||||||
{
|
{
|
||||||
float start = DrawOrigin.Y;
|
float start = DrawOrigin.Y;
|
||||||
@ -337,11 +462,30 @@ namespace Sunny.UI
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (BarOption.ToolTip == null) return;
|
if (BarOption.ToolTip == null) return;
|
||||||
if (e.Location.X > BarOption.Grid.Left && e.Location.X < Width - BarOption.Grid.Right
|
if (e.Location.X > BarOption.Grid.Left &&
|
||||||
&& e.Location.Y > BarOption.Grid.Top &&
|
e.Location.X < Width - BarOption.Grid.Right &&
|
||||||
e.Location.Y < Height - BarOption.Grid.Bottom)
|
e.Location.Y > BarOption.Grid.Top &&
|
||||||
|
e.Location.Y < Height - BarOption.Grid.Bottom)
|
||||||
{
|
{
|
||||||
SelectIndex = (int)((e.Location.X - BarOption.Grid.Left) / DrawBarWidth);
|
if (BarOption.AutoSizeBars)
|
||||||
|
{
|
||||||
|
float startX = DrawOrigin.X;
|
||||||
|
for (int i = 0; i < BarOption.Series.Count; i++)
|
||||||
|
{
|
||||||
|
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
|
||||||
|
if (e.Location.X >= startX && e.Location.X < startX + w)
|
||||||
|
{
|
||||||
|
SelectIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
startX += w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectIndex = (int)((e.Location.X - BarOption.Grid.Left) / DrawBarWidth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -374,6 +518,41 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void DrawToolTip(Graphics g)
|
||||||
|
{
|
||||||
|
if (selectIndex < 0) return;
|
||||||
|
|
||||||
|
if (BarOption.AutoSizeBars)
|
||||||
|
{
|
||||||
|
float startX = DrawOrigin.X;
|
||||||
|
|
||||||
|
for (int i = 0; i < BarOption.SeriesCount; i++)
|
||||||
|
{
|
||||||
|
float w = DrawSize.Width * BarOption.Series[i].Data.Count * 1.0f / DataCount;
|
||||||
|
|
||||||
|
if (i == selectIndex)
|
||||||
|
{
|
||||||
|
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Line)
|
||||||
|
{
|
||||||
|
float x = startX + w / 2.0f;
|
||||||
|
g.DrawLine(ChartStyle.ToolTipShadowColor, x, DrawOrigin.Y, x, BarOption.Grid.Top);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BarOption.ToolTip.AxisPointer.Type == UIAxisPointerType.Shadow)
|
||||||
|
{
|
||||||
|
g.FillRectangle(ChartStyle.ToolTipShadowColor, startX, BarOption.Grid.Top, w, Height - BarOption.Grid.Top - BarOption.Grid.Bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
startX += w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base.DrawToolTip(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void CreateEmptyOption()
|
protected override void CreateEmptyOption()
|
||||||
{
|
{
|
||||||
if (emptyOption != null) return;
|
if (emptyOption != null) return;
|
||||||
@ -381,7 +560,7 @@ namespace Sunny.UI
|
|||||||
UIBarOption option = new UIBarOption();
|
UIBarOption option = new UIBarOption();
|
||||||
option.Title = new UITitle();
|
option.Title = new UITitle();
|
||||||
option.Title.Text = "SunnyUI";
|
option.Title.Text = "SunnyUI";
|
||||||
option.Title.SubText = "BarChart";
|
option.Title.SubText = "BarChartEx";
|
||||||
|
|
||||||
//设置Legend
|
//设置Legend
|
||||||
option.Legend = new UILegend();
|
option.Legend = new UILegend();
|
||||||
|
@ -41,8 +41,16 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public readonly List<UIScaleLine> YAxisScaleLines = new List<UIScaleLine>();
|
public readonly List<UIScaleLine> YAxisScaleLines = new List<UIScaleLine>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// BarChartEx用,固定每个序列Bar个数
|
||||||
|
/// </summary>
|
||||||
public int FixedSeriesCount { get; set; } = 0;
|
public int FixedSeriesCount { get; set; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// BarChartEx用,自动调整为显示每个Bar等宽
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoSizeBars { get; set; }
|
||||||
|
|
||||||
public void AddSeries(UIBarSeries series)
|
public void AddSeries(UIBarSeries series)
|
||||||
{
|
{
|
||||||
Series.Add(series);
|
Series.Add(series);
|
||||||
@ -98,8 +106,14 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Scale { get; set; }
|
public bool Scale { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 坐标轴刻度
|
||||||
|
/// </summary>
|
||||||
public UIAxisTick AxisTick = new UIAxisTick();
|
public UIAxisTick AxisTick = new UIAxisTick();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 坐标轴标签
|
||||||
|
/// </summary>
|
||||||
public UIAxisLabel AxisLabel = new UIAxisLabel();
|
public UIAxisLabel AxisLabel = new UIAxisLabel();
|
||||||
|
|
||||||
public bool MaxAuto { get; set; } = true;
|
public bool MaxAuto { get; set; } = true;
|
||||||
|
@ -40,6 +40,19 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ImageEx
|
public static class ImageEx
|
||||||
{
|
{
|
||||||
|
public static Bitmap ChangeOpacity(Image img, float opacity)
|
||||||
|
{
|
||||||
|
Bitmap bmp = new Bitmap(img.Width, img.Height); // Determining Width and Height of Source Image
|
||||||
|
Graphics graphics = bmp.Graphics();
|
||||||
|
ColorMatrix matrix = new ColorMatrix();
|
||||||
|
matrix.Matrix33 = opacity;
|
||||||
|
ImageAttributes imgAttribute = new ImageAttributes();
|
||||||
|
imgAttribute.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
|
||||||
|
graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute);
|
||||||
|
graphics.Dispose(); // Releasing all resource used by graphics
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
public static ImageList GetToolbarImageList(Type type, Bitmap bitmap, Size imageSize, Color transparentColor)
|
public static ImageList GetToolbarImageList(Type type, Bitmap bitmap, Size imageSize, Color transparentColor)
|
||||||
{
|
{
|
||||||
ImageList imageList = new ImageList();
|
ImageList imageList = new ImageList();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user