How can I fix the number of MinorGrid lines to a fixed number in Microsoft's .NET 4.0 Chart?

拥有回忆 提交于 2019-12-13 19:18:32

问题


I am trying to set a fixed number of minor grid lines in a .NET 4.0 Chart whose X axis is in a Logarithmic scale.

I try to set the "Axis.Minor.Interval" property, this only makes the grid lines disappear.

chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
            chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Number;
            chart1.ChartAreas[0].AxisX.Interval = 100d;

            chart1.ChartAreas[0].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Number;
            chart1.ChartAreas[0].AxisX.MajorGrid.IntervalOffsetType = DateTimeIntervalType.Number;
            chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 10d;

            chart1.ChartAreas[0].AxisX.MinorGrid.IntervalType = DateTimeIntervalType.Number;
            chart1.ChartAreas[0].AxisX.MinorGrid.IntervalOffsetType = DateTimeIntervalType.Number;
            chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 5;

My goal is to have a logarithmic scale with a major grid every decade, showing 10 minor grid lines.

Thanks


回答1:


After hours of banging my head on the wall with the same exact problem, it seems I've stumbled onto the answer:

Inexplicably, if you set the MinorGrid Interval to 1, then you get the traditional Logarithmic grid marks, ten per decade:

aChart.ChartAreas[0].AxisX.IsLogarithmic = true;
aChart.ChartAreas[0].AxisX.MinorGrid.Interval = 1;
aChart.ChartAreas[0].AxisX.MinorGrid.Enabled = true;

Hope that helps.



来源:https://stackoverflow.com/questions/11694521/how-can-i-fix-the-number-of-minorgrid-lines-to-a-fixed-number-in-microsofts-ne

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!