OxyPlot.如何将轴旁边的值格式从1000更改为1k

mid*_*007 3 string-formatting oxyplot

我试图将轴旁边的值的格式从例如1000更改为1k或1000000到1M.

这在LinearAxis中是否可行?

这是我的代码:

            m.Axes.Add(new LinearAxis
        {
            Position = AxisPosition.Right,
            IsZoomEnabled = false,
            IsPanEnabled = false,
            Minimum = -(_maxPointValue2*0.1),
            Maximum = _maxPointValue2 + (_maxPointValue2*0.1),
            FontSize = 15,
            Key = "right",
            TickStyle = TickStyle.Outside,

        });
Run Code Online (Sandbox Code Playgroud)

这可能与StringFormat一起使用吗?

也可以更改TickStyle,以便破折号通过整个情节?

提前致谢

迈克尔

小智 7

您可以使用Axis类的LabelFormatter属性从1000更改为1K等.

创建格式化函数以获取double并返回一个字符串:

private static string _formatter(double d)
    {
        if (d < 1E3)
        {
            return String.Format("{0}", d);
        }
        else if (d >= 1E3 && d < 1E6)
        {
            return String.Format("{0}K", d / 1E3);
        }
        else if (d >= 1E6 && d < 1E9)
        {
            return String.Format("{0}M", d / 1E6);
        }
        else if (d >= 1E9)
        {
            return String.Format("{0}B", d / 1E9);
        }
        else
        {
            return String.Format("{0}", d);
        }
    }
Run Code Online (Sandbox Code Playgroud)

然后将其添加到Axis类:

plotmodel.Axes.Add(new LinearAxis
        {
            //Other properties here
            LabelFormatter = _formatter,
        });
Run Code Online (Sandbox Code Playgroud)