gpt4 book ai didi

string-formatting - 氧图。如何将轴旁边的值格式从 1000 更改为 1k

转载 作者:行者123 更新时间:2023-12-04 09:01:02 25 4
gpt4 key购买 nike

我正在尝试将轴旁边的值的格式从例如 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,

});

StringFormat 是否可以做到这一点?

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

提前致谢

迈克尔

最佳答案

您可以使用 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);
}
}

然后将其添加到Axis类中:

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

关于string-formatting - 氧图。如何将轴旁边的值格式从 1000 更改为 1k,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30349725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com