Sjips
Sjips

Reputation: 1258

Axis values formatting for chart

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.

Upvotes: 5

Views: 11956

Answers (1)

Dmitry
Dmitry

Reputation: 14059

Set the LabelStyle.Format property:

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

Or

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

Upvotes: 9

Related Questions