0
votes

I am trying to construct a chart using the native ASP.NET 4.0 charting control.

I've done nearly everything I wanted to do, but if you look at the following screenshot:

enter image description here

You'll notice that the Y axis labels are all wonky - that is, they are decimals, and they don't fall directly on any of the actual gridlines.

The purpose of my chart is to show a value that will always be between 0 and 16. I need to know the exact value, so I was able to set the gridlines to represent each value, by using this code:

Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 1;

As you can see, it is showing all lines, 0 to 16. However, the Y axis labels not only do not line up, but aren't even whole values. I would like there to be a label for EACH gridline, and I'd like them to be whole values.

I've done my share of googling, but I mostly find stuff pertaining to turning off the gridlines altogether, which is not what I want.

Any ideas?

2

2 Answers

0
votes

can you not just set AxisY.Interval?

chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 1;
chart1.ChartAreas["ChartArea1"].AxisY.Interval = 1;

I created a test chart quick and got the following:

enter image description here

0
votes

When I set the interval, I only set the property for the Axis Interval property

chart1.ChartAreas["ChartArea1"].AxisY.Interval = 1;

The default behavior sets the major grid and major tick to this interval unless you have otherwise overridden a property that turns auto off for everything. Microsoft Charting aka Dundas charting (where Microsoft got the code) can be tricky this way.

While I cannot speak for every property within Microsoft Charting, it helps to set the most non-specific property you can find. Only go deeper if you do not get the desired result as going deeper can have unintended consequences by overriding the defaults which generally work quite well.

i.e.:

chart1.ChartAreas["ChartArea1"].AxisY.Interval = 1;

instead of

chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 1;