* UILineChart: X轴支持字符串显示
This commit is contained in:
parent
3276cd2635
commit
47450a3880
Binary file not shown.
Binary file not shown.
@ -219,14 +219,17 @@ namespace Sunny.UI.Demo
|
|||||||
option.Y2Axis.AxisLabel.DecimalCount = 1;
|
option.Y2Axis.AxisLabel.DecimalCount = 1;
|
||||||
option.Y2Axis.AxisLabel.AutoFormat = false;
|
option.Y2Axis.AxisLabel.AutoFormat = false;
|
||||||
|
|
||||||
|
|
||||||
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 3.5 });
|
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 3.5 });
|
||||||
option.Y2AxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = 12, DashDot = true });
|
option.Y2AxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = 12, DashDot = true });
|
||||||
|
|
||||||
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Lime, Name = "3", Value = 3 });
|
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Lime, Name = "3", Value = 3 });
|
||||||
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "6", Value = 6 });
|
option.XAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "6", Value = 6 });
|
||||||
|
|
||||||
option.XAxis.CustomLabels = new CustomLabels(0, 2, 10);
|
option.XAxis.CustomLabels = new CustomLabels(1, 1, 11);
|
||||||
|
for (int i = 1; i <= 12; i++)
|
||||||
|
{
|
||||||
|
option.XAxis.CustomLabels.AddLabel(i + "月");
|
||||||
|
}
|
||||||
|
|
||||||
LineChart.SetOption(option);
|
LineChart.SetOption(option);
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,17 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
Labels.Add(label);
|
Labels.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearLabels()
|
||||||
|
{
|
||||||
|
Labels.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetLabel(int i)
|
||||||
|
{
|
||||||
|
if (i < Labels.Count) return Labels[i];
|
||||||
|
else return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UIAxisLabel
|
public class UIAxisLabel
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
* 2021-10-14: V3.0.8 修改图线显示超出范围的问题
|
* 2021-10-14: V3.0.8 修改图线显示超出范围的问题
|
||||||
* 2021-12-30: V3.0.9 增加双Y坐标轴
|
* 2021-12-30: V3.0.9 增加双Y坐标轴
|
||||||
* 2021-12-31: V3.0.9 增加坐标线、图线边框等是否显示的设置
|
* 2021-12-31: V3.0.9 增加坐标线、图线边框等是否显示的设置
|
||||||
|
* 2021-12-31: V3.0.9 增加自定义坐标轴刻度
|
||||||
|
* 2021-12-31: V3.0.9 X轴支持字符串显示
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -271,6 +273,7 @@ namespace Sunny.UI
|
|||||||
double[] XLabels = Option.XAxis.HaveCustomLabels ? Option.XAxis.CustomLabels.LabelValues() : XScale.CalcLabels();
|
double[] XLabels = Option.XAxis.HaveCustomLabels ? Option.XAxis.CustomLabels.LabelValues() : XScale.CalcLabels();
|
||||||
float[] labels = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width);
|
float[] labels = XScale.CalcXPixels(XLabels, DrawOrigin.X, DrawSize.Width);
|
||||||
|
|
||||||
|
float xr = 0;
|
||||||
for (int i = 0; i < labels.Length; i++)
|
for (int i = 0; i < labels.Length; i++)
|
||||||
{
|
{
|
||||||
float x = labels[i];
|
float x = labels[i];
|
||||||
@ -294,8 +297,19 @@ namespace Sunny.UI
|
|||||||
label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalCount);
|
label = XLabels[i].ToString("F" + Option.XAxis.AxisLabel.DecimalCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Option.XAxis.HaveCustomLabels && Option.XAxis.CustomLabels.GetLabel(i).IsValid())
|
||||||
|
{
|
||||||
|
label = Option.XAxis.CustomLabels.GetLabel(i);
|
||||||
|
}
|
||||||
|
|
||||||
SizeF sf = g.MeasureString(label, TempFont);
|
SizeF sf = g.MeasureString(label, TempFont);
|
||||||
g.DrawString(label, TempFont, ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
float xx = x - sf.Width / 2.0f;
|
||||||
|
|
||||||
|
if (xx > xr && xx + sf.Width < Width)
|
||||||
|
{
|
||||||
|
xr = xx + sf.Width;
|
||||||
|
g.DrawString(label, TempFont, ForeColor, xx, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Option.XAxis.AxisTick.Show)
|
if (Option.XAxis.AxisTick.Show)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user