在相同的图表区域中,条形图和折线图不同步 [英] Bar and Line charts are not synced when in the same chart area

查看:355
本文介绍了在相同的图表区域中,条形图和折线图不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net的图表有问题。问题是线和条在图表区域中不同步。我附上了一张照片,以说明我的意思。



这里是我填充图表的代码。我从数据库获取数据。

 将日期作为日期调整
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))

接下来

解决方案

线和列系列具有相同的XValues,这就是它们的中心对齐的原因。你需要为两个系列生成不同的XValues。由小边距偏移的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}
pre>

我使用0.2的差异,但是这将是不同的在你的情况下(特别是因为它似乎你有日期轴设置?这将把线系列推向左边。



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



这是XY图表的值。正如你可以看到,我把x值向左移动0.2。


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

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

解决方案

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:

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.

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.

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

这篇关于在相同的图表区域中,条形图和折线图不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆