.net MSChart:标签格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6256310/
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
MSChart: Label format
提问by Dumitru
How can I format chart label? I need to see only 2 digits after point.
如何格式化图表标签?我只需要看到点后的 2 位数字。
I try chart.ChartAreas.First().AxisY.LabelStyle.Format = "#.##";and 0.00
我试着chart.ChartAreas.First().AxisY.LabelStyle.Format = "#.##";和0.00
Also I try to set Series[0].LabelFormat = "0.00"and #.##
我也尝试设置Series[0].LabelFormat = "0.00"和#.##
and without success.
并且没有成功。
What is wrong?
怎么了?


回答by Cain
Try setting .AxisX.LabelStyle.Formatto "{0:0.00}"- I had to do it recently on one of my charts so it should work.
尝试设置.AxisX.LabelStyle.Format为"{0:0.00}"- 我最近必须在我的一张图表上进行设置,因此它应该可以工作。
回答by LVEYO
try this
尝试这个
chart.ChartAreas.First().AxisY.LabelStyle.Format = "F2";
and the details on this page http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
以及此页面上的详细信息 http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
回答by Tom
You could also iterate over your list. Here is what I did for percentages:
您也可以遍历您的列表。这是我为百分比所做的:
foreach (var point in Chart.Series[0].Points)
{
point.Label = point.YValues[0].ToString("P2");
point.LegendText = point.YValues[0].ToString("P2") + " - " + point.AxisLabel;
}
Set
放
回答by user2839800
Set the YValueType="Double" and the LabelFormat="C" within the tag.
在标签中设置 YValueType="Double" 和 LabelFormat="C"。

