数据将数组绑定到 vb.net 中的图表系列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24758837/
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
Data bind an array to a chart series in vb.net
提问by Luminous
How do you data bind a Series to an array of numbers?
如何将系列数据绑定到数字数组?
Following this answerI would've hoped it'd be that easy, but it's not.
按照这个答案,我希望它会那么容易,但事实并非如此。
My basic code example:
我的基本代码示例:
dim xarray = {2, 30, 40, 50}
dim yarray = {1, 20, 40, 10}
dim newSeries = new DataVisualization.Charting.Series()
newSeries.ChartType = DataVisualization.Charting.SeriesChartType.Line
newSeries.points.DataBindXY(xarray, yarray)
xarray = {1,2,3,4}
myChart.series.add(newSeries)
Throwing this into a debugger and stepping through you see the two arrays are successfully apart of the series. After the 6th line of code, going back to see if the series was updated shows it wasn't. In my code I have to go digging for these two arrays which reside in a BindingList, but the concept is the same since I'm still working with arrays.
将其放入调试器并逐步执行,您会看到这两个数组已成功地从该系列中分离出来。在第 6 行代码之后,返回查看该系列是否更新显示它没有更新。在我的代码中,我必须挖掘位于 BindingList 中的这两个数组,但概念是相同的,因为我仍在使用数组。
回答by Sifu
vb.netis a line by line programming language. Sadly, your
vb.net是一种逐行的编程语言。可悲的是,你的
newSeries.points.DataBindXY(xarray, yarray)
actually codes:
实际上代码:
newSeries.points.DataBindXY({2, 30, 40, 50} , {1, 20, 40, 10}).
So, modifying later on xarraywon't modify the chart. Everytime you modify xarrayor yarray, you have the call DatabindXY.
因此,稍后xarray修改不会修改图表。每次修改xarrayor 时yarray,都会调用DatabindXY。
So, to work, it would have to be :
所以,要工作,它必须是:
dim xarray = {2, 30, 40, 50}
dim yarray = {1, 20, 40, 10}
dim newSeries = new DataVisualization.Charting.Series()
newSeries.ChartType = DataVisualization.Charting.SeriesChartType.Line
newSeries.points.DataBindXY(xarray, yarray)
xarray = {1,2,3,4}
newSeries.points.DataBindXY(xarray, yarray)
myChart.series.add(newSeries)

