Search code examples
c#data-visualizationmschartdundas

Microsoft chart grid lines not drawn at 'whole' numbers


When the Microsoft chart control is zoomed in, the values of the labels and grid lines often looks like 38.2, 39.2, 40.2, 41.2 ... rather than 38,39,40,41. I tried to set the interval offset to correct this by using the code shown below without success.

myChart.ChartAreas[0].AxisX.MinorGrid.IntervalOffset = myChart.ChartAreas[0].AxisY.ScaleView.ViewMinimum % 1;
myChart.ChartAreas[0].AxisX.IntervalOffset = myChart.ChartAreas[0].AxisY.ScaleView.ViewMinimum % 1;

What is the proper way to get the major and minor grid-lines and labels to be drawn starting at a specific value?


Solution

  • Your problems might be caused by margins being added. Make sure you set

    myChart.ChartArea[0].AxisX.IsMarginVisible = false;