Lock MSChart Gridlines
How do I do the following with an MSChart?
- 开发者_StackOverflow社区
- Set axes to x: [0 - 1000] and y: [0 - 1].
- Show the gridlines when chart has no points.
- Disable auto adjusting of gridlines.
Note: Setting Axis(X/Y).(Min/Max)imum seems to have no effect if a point exists inside the bounds.
Question 1) is nicely answered by Bentley Davis, by setting the min and max values of the X and Y axes.
Question 3) requires one more property for each axis; the .Interval property. If you do not set the Interval, the MSChart will automatically do a best-fit interval between your declared min and max, thus potentially changing the positioning of the gridlines and the labels.
Chart1.Legends.Clear()
Chart1.Series("Series1").ChartType = SeriesChartType.FastLine
With Chart1.ChartAreas(0)
.AxisX.Maximum = 1000
.AxisX.Minimum = 0
.AxisY.Maximum = 1
.AxisY.Minimum = 0
.AxisX.Interval = 200
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Chart1.Series("Series1").Points.AddXY(100, 0.5)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Chart1.Series("Series1").Points.AddXY(200, 0.6)
End Sub
Question 2): You must add at least 1 data point to some series to display the gridlines. There is no way around this. I add the following series to my Charts when I want to duplicate that behavoir:
Dim nSer As Series = Chart1.Series.Add("fake_Series")
nSer.ChartType = SeriesChartType.Point
nSer.MarkerSize = 0
nSer.Points.Add(2000, 2)
The point does not display on the chart, but the gridlines are displayed.
I am not able to recreate your problem. When I set the axes and the grid lines display then I add points the grid lines to not chnage. You seem to say that they do change. Here is the code I am using. I might be able to help if I can see example code.
Chart1.Series("Series1").ChartType = SeriesChartType.FastLine
Chart1.ChartAreas(0).AxisX.Maximum = 1000
Chart1.ChartAreas(0).AxisX.Minimum = 0
Chart1.ChartAreas(0).AxisY.Maximum = 1
Chart1.ChartAreas(0).AxisY.Minimum = 0
Chart1.Series("Series1").Points.AddXY(100, 0.5)
Chart1.Series("Series1").Points.AddXY(200, 0.6)
精彩评论