* UIBarChartEx:增加X轴标签旋转角度

This commit is contained in:
Sunny 2020-12-07 21:33:09 +08:00
parent 64c9f6aeb4
commit 40ee06facd
6 changed files with 17 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -28,7 +28,7 @@ namespace Sunny.UI.Demo
{
UIBarOption option = new UIBarOption();
option.Grid.Bottom = 60;
option.Grid.Bottom = 65;
option.Title = new UITitle();
option.Title.Text = "SunnyUI";
@ -76,10 +76,11 @@ namespace Sunny.UI.Demo
option.ToolTip.Visible = true;
option.YAxis.Scale = true;
option.XAxis.Name = "日期";
option.XAxis.Name = "";
option.YAxis.Name = "数值";
option.XAxis.AxisTick.Distance = 14;
option.XAxis.AxisLabel.Angle = 90;
option.FixedSeriesCount = 3;
option.AutoSizeBars = true;

View File

@ -583,7 +583,11 @@ namespace Sunny.UI
{
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 + 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;
}
}
@ -593,7 +597,11 @@ namespace Sunny.UI
foreach (var data in Option.Series)
{
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;
}
}

View File

@ -165,6 +165,8 @@ namespace Sunny.UI
public event DoFormatter Formatter;
public int Angle { get; set; } = 0;
public string GetLabel(double value, int index, UIAxisType axisType = UIAxisType.Value)
{
switch (axisType)

View File

@ -455,8 +455,8 @@ namespace Sunny.UI
}
SizeF sf = g.MeasureString(line.Name, SubFont);
float x = pos - sf.Width - 4;
if (x < Option.Grid.Left) x = pos + 4;
float x = pos - sf.Width;
if (x < Option.Grid.Left) x = pos + 2;
float y = Option.Grid.Top + 4 + sf.Height * idx;
if (y > Height - Option.Grid.Bottom)
{