C# 格式化图表轴标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18025263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Formatting chart axis labels
提问by SlimPDX
I'm making some charts in C# Visual Studio 2010 and I had a quick (hopefully simple) question about formatting the labels on the X-Axis. I searched SO and Google for an answer and I'm pretty sure it has to do with simply editing the LabelStyle.Format for a chart area... But I can't figure it out! Okay, too much information, let me get on with the question
我正在 C# Visual Studio 2010 中制作一些图表,我有一个关于在 X 轴上格式化标签的快速(希望很简单)问题。我在 SO 和 Google 上搜索了答案,我很确定这与简单地编辑图表区域的 LabelStyle.Format 有关......但我无法弄清楚!好吧,信息太多了,让我继续提问
In short, my chart needs to have mileage on the x-axis and it ranges from 0 to 240,000. I would really like to spruce it up a bit and have a 'K' instead of the trailing 3 zeroes. Example: 60K, 120k, 180K, 240K.
简而言之,我的图表需要在 x 轴上有里程数,范围从 0 到 240,000。我真的很想把它修饰一下,用一个“K”而不是后面的 3 个零。示例:60K、120k、180K、240K。
采纳答案by DasKrümelmonster
Set the LabelStyle.Format property accordingly:
相应地设置 LabelStyle.Format 属性:
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{0:0,}K";
Documentation is here: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx(Section: "The ',' Custom Specifier")
文档在这里:http: //msdn.microsoft.com/en-us/library/0c899ak8.aspx(部分:“','自定义说明符”)