带有绑定图表的.net代码问题

时间:2012-04-27 17:46:08

标签: .net vb.net

我试图用下面的代码绑定telerik图表,然后按照屏幕截图显示错误。

任何人都知道如何处理此错误。

逻辑说明:我将数据表指定为 listdata 数据源,并尝试根据表行计数绑定数据。

Dim listdata As new DataList 
        listdata.DataSource   = ds.Tables.Item(0)

        BaselineRadChart.Clear()    
        Dim chartSeries As New ChartSeries("Baseline", ChartSeriesType.Line) 
            chartSeries.Appearance.ShowLabels = False
            Dim i As Integer = 0
            While i < ds.Tables(0).Rows.Count
                chartSeries.AddItem(New ChartSeriesItem(listData[i].x, listData[i].y))
                i = i + 1
            End While  

            BaselineRadChart.AddChartSeries(chartSeries)
            BaselineRadChart.ChartTitle.TextBlock.Text = title
            BaselineRadChart.PlotArea.XAxis.AxisLabel.TextBlock.Text = xaxislableName
            BaselineRadChart.PlotArea.XAxis.AxisLabel.Visible = True
            BaselineRadChart.PlotArea.XAxis.IsZeroBased = False
            BaselineRadChart.PlotArea.YAxis.AxisLabel.TextBlock.Text = yaxislableName
            BaselineRadChart.PlotArea.YAxis.AxisLabel.Visible = True
            BaselineRadChart.PlotArea.YAxis.IsZeroBased = True  

我试图通过使用下面的参考代码来开发上面的代码(bcz我们相同的功能,如果下面的代码工作,肯定我的代码工作)。这对他有用。

ChartSeries chartSeries = new ChartSeries("Altitude", ChartSeriesType.Line); 
chartSeries.Appearance.ShowLabels = false; 
incrementCount = 1; 

for (int i = 0; i < listData.Count; i = i + incrementCount) 
    {
        chartSeries.AddItem(new ChartSeriesItem(listData[i].x, listData[i].y)); 
    }

RadChart2.AddChartSeries(chartSeries);
RadChart2.ChartTitle.TextBlock.Text = title;
RadChart2.PlotArea.XAxis.AxisLabel.TextBlock.Text = 
"Distance (Miles)"; 
RadChart2.PlotArea.XAxis.AxisLabel.Visible = true; 
RadChart2.PlotArea.XAxis.IsZeroBased = true; 
RadChart2.PlotArea.YAxis.AxisLabel.TextBlock.Text = yAxisLabel;
RadChart2.PlotArea.YAxis.AxisLabel.Visible = true; 
RadChart2.PlotArea.YAxis.IsZeroBased = false; 

enter image description here

1 个答案:

答案 0 :(得分:0)

你不是要从表中提取数据吗?

While i < ds.Tables(0).Rows.Count
    chartSeries.AddItem(New ChartSeriesItem(_
        ds.Tables(0).Rows(i)("x"), ds.Tables(0).Rows(i)("y")))
    '               ^^^^^^^^^^^^^ get from the tabel
    i = i + 1
End While