锁定MSChart网格线 [英] Lock MSChart Gridlines
问题描述
如何使用MSChart执行以下操作?
How do I do the following with an MSChart?
- 将轴设置为x:[0-1000]和y:[0-1].
- 当图表没有点时显示网格线.
- 禁用网格线的自动调整.
注意:设置轴(X/Y).如果边界内存在点,则(Min/Max)imum似乎无效.
Note: Setting Axis(X/Y).(Min/Max)imum seems to have no effect if a point exists inside the bounds.
推荐答案
问题1).
问题3)每个轴还需要一个属性; .Interval属性.如果未设置时间间隔,则MSChart会自动在您声明的最小值和最大值之间进行最佳匹配,从而可能会更改网格线和标签的位置.
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
问题2): 您必须至少向一个序列中添加1个数据点才能显示网格线.没有办法解决这个问题.当我想复制该行为时,将以下系列添加到图表中:
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.
这篇关于锁定MSChart网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!