问题
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