.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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:37:18  来源:igfitidea点击:

MSChart: Label format

.netmschart

提问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?

怎么了?

current chart

当前图表

回答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"。