Bar and Line charts are not synced when in the same chart area

≡放荡痞女 提交于 2019-12-25 04:28:18

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/22201052/bar-and-line-charts-are-not-synced-when-in-the-same-chart-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!