氧图.如何将轴旁边的值的格式从 1000 更改为 1k [英] OxyPlot. How to change Format of values next to the axis from 1000 to 1k

查看:36
本文介绍了氧图.如何将轴旁边的值的格式从 1000 更改为 1k的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将轴旁边的值的格式从 1000 更改为 1k,或者将 1000000 更改为 1M.

Im trying to change the format of the value next to the axis from for example 1000 to 1k or 1000000 to 1M.

这在 LinearAxis 中可行吗?

Is this possible in 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,

        });

这可能用 StringFormat 实现吗?

Is this perhaps possible with StringFormat?

是否也可以更改 TickStyle,使破折号贯穿整个情节?

Also is it possible to change the TickStyle, so that the dashes going trough the whole plot?

提前致谢

迈克尔

推荐答案

可以使用Axis类的LabelFormatter属性将1000改为1K等

You can use the LabelFormatter property of the Axis class to change from 1000 to 1K etc.

创建格式化函数以获取双精度值并返回字符串:

Create your formatting function to take a double and return a string:

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);
        }
    }

然后将其添加到Axis类中:

Then add it to the Axis class:

plotmodel.Axes.Add(new LinearAxis
        {
            //Other properties here
            LabelFormatter = _formatter,
        });

这篇关于氧图.如何将轴旁边的值的格式从 1000 更改为 1k的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆