Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axis values formatting for chart

Tags:

c#

graph

winforms

In my WinForms project I use the standard Chart control (from the VS toolbox) to display pressure versus time. 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:

enter image description here

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? I can also live with values like: 7.98, 9.98, 11.98, so with a limited number of decimals.

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.

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). I use for both series the FastLine type of graph. I enabled the zooming by setting IsUserEnabled and IsUSerSelection to true for CursorX and CursorY in the graph designer. As said, this works, but I could not spot a property to customize the format of the values.

like image 365
Sjips Avatar asked Nov 22 '14 20:11

Sjips


1 Answers

Set the LabelStyle.Format property:

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

Or

chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{0:0.00}";
like image 146
Dmitry Avatar answered Sep 20 '22 12:09

Dmitry