锁定 MSChart 网格线

发布于 2024-08-21 21:48:51 字数 179 浏览 6 评论 0原文

如何使用 MSChart 执行以下操作?

  1. 将轴设置为 x:[0 - 1000] 和 y:[0 - 1]。
  2. 当图表没有点时显示网格线。
  3. 禁用网格线的自动调整。

注意:如果边界内存在点,设置 Axis(X/Y).(Min/Max)imum 似乎没有效果。

How do I do the following with an MSChart?

  1. Set axes to x: [0 - 1000] and y: [0 - 1].
  2. Show the gridlines when chart has no points.
  3. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抽个烟儿 2024-08-28 21:48:51

Bentley Davis 通过设置 X 轴和 Y 轴的最小值和最大值很好地回答了问题 1)。

问题3)要求每个轴多一个属性; .Interval 属性。如果您不设置间隔,MSChart 将自动在声明的最小值和最大值之间设置最佳拟合间隔,从而可能会更改网格线和标签的位置。

  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 个数据点才能显示网格线。这是没有办法解决的。当我想要复制该行为时,我将以下系列添加到我的图表中:

  Dim nSer As Series = Chart1.Series.Add("fake_Series")
  nSer.ChartType = SeriesChartType.Point
  nSer.MarkerSize = 0
  nSer.Points.Add(2000, 2)

该点不显示在图表上,但显示网格线。

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.

请爱~陌生人 2024-08-28 21:48:51

我无法重现您的问题。当我设置轴并显示网格线时,我将网格线添加点以不改变。你似乎说他们确实改变了。这是我正在使用的代码。如果我能看到示例代码,我也许可以提供帮助。

    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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文