* UIBarChartEx:增加X轴标签旋转角度
This commit is contained in:
parent
64c9f6aeb4
commit
40ee06facd
Binary file not shown.
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
@ -28,7 +28,7 @@ namespace Sunny.UI.Demo
|
|||||||
{
|
{
|
||||||
UIBarOption option = new UIBarOption();
|
UIBarOption option = new UIBarOption();
|
||||||
|
|
||||||
option.Grid.Bottom = 60;
|
option.Grid.Bottom = 65;
|
||||||
|
|
||||||
option.Title = new UITitle();
|
option.Title = new UITitle();
|
||||||
option.Title.Text = "SunnyUI";
|
option.Title.Text = "SunnyUI";
|
||||||
@ -76,10 +76,11 @@ namespace Sunny.UI.Demo
|
|||||||
option.ToolTip.Visible = true;
|
option.ToolTip.Visible = true;
|
||||||
option.YAxis.Scale = true;
|
option.YAxis.Scale = true;
|
||||||
|
|
||||||
option.XAxis.Name = "日期";
|
option.XAxis.Name = "";
|
||||||
option.YAxis.Name = "数值";
|
option.YAxis.Name = "数值";
|
||||||
|
|
||||||
option.XAxis.AxisTick.Distance = 14;
|
option.XAxis.AxisTick.Distance = 14;
|
||||||
|
option.XAxis.AxisLabel.Angle = 90;
|
||||||
|
|
||||||
option.FixedSeriesCount = 3;
|
option.FixedSeriesCount = 3;
|
||||||
option.AutoSizeBars = true;
|
option.AutoSizeBars = true;
|
||||||
|
@ -583,7 +583,11 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
float w = DrawSize.Width * data.Data.Count * 1.0f / DataCount;
|
float w = DrawSize.Width * data.Data.Count * 1.0f / DataCount;
|
||||||
SizeF sf = g.MeasureString(data.Name, SubFont);
|
SizeF sf = g.MeasureString(data.Name, SubFont);
|
||||||
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
|
if (Option.XAxis.AxisLabel.Angle != 0)
|
||||||
|
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, new PointF(start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.Grid.Bottom / 2.0f),
|
||||||
|
new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360);
|
||||||
|
else
|
||||||
|
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
|
||||||
start += w;
|
start += w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -593,7 +597,11 @@ namespace Sunny.UI
|
|||||||
foreach (var data in Option.Series)
|
foreach (var data in Option.Series)
|
||||||
{
|
{
|
||||||
SizeF sf = g.MeasureString(data.Name, SubFont);
|
SizeF sf = g.MeasureString(data.Name, SubFont);
|
||||||
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
|
if (Option.XAxis.AxisLabel.Angle != 0)
|
||||||
|
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, new PointF(start - sf.Width / 2.0f, DrawOrigin.Y + Option.Grid.Bottom / 2.0f),
|
||||||
|
new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360);
|
||||||
|
else
|
||||||
|
g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance);
|
||||||
start += DrawBarWidth;
|
start += DrawBarWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,8 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public event DoFormatter Formatter;
|
public event DoFormatter Formatter;
|
||||||
|
|
||||||
|
public int Angle { get; set; } = 0;
|
||||||
|
|
||||||
public string GetLabel(double value, int index, UIAxisType axisType = UIAxisType.Value)
|
public string GetLabel(double value, int index, UIAxisType axisType = UIAxisType.Value)
|
||||||
{
|
{
|
||||||
switch (axisType)
|
switch (axisType)
|
||||||
|
@ -455,8 +455,8 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
SizeF sf = g.MeasureString(line.Name, SubFont);
|
SizeF sf = g.MeasureString(line.Name, SubFont);
|
||||||
float x = pos - sf.Width - 4;
|
float x = pos - sf.Width;
|
||||||
if (x < Option.Grid.Left) x = pos + 4;
|
if (x < Option.Grid.Left) x = pos + 2;
|
||||||
float y = Option.Grid.Top + 4 + sf.Height * idx;
|
float y = Option.Grid.Top + 4 + sf.Height * idx;
|
||||||
if (y > Height - Option.Grid.Bottom)
|
if (y > Height - Option.Grid.Bottom)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user