简体   繁体   English

轴值格式化图表

[英]Axis values formatting for chart

In my WinForms project I use the standard Chart control (from the VS toolbox) to display pressure versus time. 在我的WinForms项目中,我使用标准的Chart控件(来自VS工具箱)来显示压力与时间的关系。 It must be possible to zoom the graph. 必须可以缩放图表。 This works fine, but the X-axis values in the zoomed graph shows the values in a lot of decimals: 这工作正常,但缩放图中的X轴值显示了许多小数的值:

在此输入图像描述

Does anyone have an idea what I can show the values in a better format? 有谁知道我能用更好的格式显示值? For example, in the above graph I would see labels like: 8.00, 10.00, 12.00? 例如,在上图中我会看到如下标签:8.00,10.00,12.00? I can also live with values like: 7.98, 9.98, 11.98, so with a limited number of decimals. 我也可以使用如下值:7.98,9.98,11.98,所以使用有限的小数。

I've looked in the control designers for the Chart control where I can specify a format string or the number of decimals, but I could not find it. 我已经在控件设计器中查看了Chart控件,我可以在其中指定格式字符串或小数位数,但我找不到它。

There is nothing special for this chart. 这张图没有什么特别之处。 It shows 2 series (not easy to see but you could probably see a blue and a green line). 它显示了2个系列(不容易看到,但你可能看到蓝色和绿色线)。 I use for both series the FastLine type of graph. 我用于两个系列的FastLine类型的图形。 I enabled the zooming by setting IsUserEnabled and IsUSerSelection to true for CursorX and CursorY in the graph designer. 我通过在图形设计器中为CursorX和CursorY设置IsUserEnabled和IsUSerSelection为真来启用缩放。 As said, this works, but I could not spot a property to customize the format of the values. 如上所述,这是有效的,但我找不到属性来自定义值的格式。

Set the LabelStyle.Format property: 设置LabelStyle.Format属性:

chart1.ChartAreas[0].AxisX.LabelStyle.Format = "0.00";

Or 要么

chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{0:0.00}";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM