vb.net 条形图和折线图在同一图表区域中不同步
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22201052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bar and Line charts are not synced when in the same chart area
提问by Lime3003
I have problem with a chart in vb.net. The problem is that line and bar are not synced in the chart area. I've attached a picture to make it clear what I mean
我在 vb.net 中遇到图表问题。问题是图表区域中的线条和条形图未同步。我附上了一张图片来说明我的意思
Here is the code where I populate the chart. I′m getting the data from a database.
这是我填充图表的代码。我正在从数据库中获取数据。
Dim theDate As Date
For i As Integer = Count - 1 To 0 Step -1
'Chart1.Series("serRxTime").Points.AddY(dv(i)(0) / 60)
theDate = dv(i)(1)
Chart1.Series("serTime").Points.AddXY(theDate.ToString("dd-MMM HH:MM", enUS), dv(i)(0) / 60)
Chart1.Series("serAdd").Points.AddY(dv(i)(2))
Next


回答by Mitja Bezen?ek
Line and column series have the same XValues that's why their centres are aligned. You would need to generate different XValues for the two series. XValues that are offset by a small margin. Something like this:
线和列系列具有相同的 XValue,这就是它们的中心对齐的原因。您需要为这两个系列生成不同的 XValue。被小幅度偏移的 XValues。像这样的东西:
Chart1.Series("serTime").XValues = {0.8, 1.8, 2.8, 3.8,,...,count - 0.2}
Chart1.Series("serAdd").XValues = {1, 2, 3, 4,..., count}
I used 0.2 difference, but this will be different in your case (especially since it seems you have date axis set?). This would push the line series to the left.
我使用了 0.2 差异,但这在您的情况下会有所不同(尤其是因为您似乎设置了日期轴?)。这会将线系列推向左侧。
I created an example for you. On the first picture you can see the data for the columns. Their x values are 1,2,3,4,...,12 and their y values are marked with blue.

我为你创建了一个例子。在第一张图片上,您可以看到列的数据。它们的 x 值为 1,2,3,4,...,12,它们的 y 值用蓝色标记。

And this is the values for the XY chart. As you can see I moved the x values by 0.2 to the left.

这是 XY 图表的值。如您所见,我将 x 值向左移动了 0.2。


