如何将数据源重新绑定到Telerik RadChartView

时间:2014-06-13 05:05:55

标签: vb.net telerik telerik-reporting

我正在使用Telerik Rad ChartView来填充销售信息。我使用以下代码saleHistoryChart.DataSource = saleHistoryDataTable设置数据源。我有一个重置按钮&当用户点击它时,我想重置数据表中的新数据。

我在表单加载和放大器上调用下面显示的populateGraph()方法。重置按钮单击事件。数据表使用数据库中的新数据正确更新,但图表仍显示旧数据。因此,如何重新绑定或重置图表以包含新数据?

Private Sub populateGraph()
Dim saleHistoryDataTable As DataTable = GETDATA("SQL HERE")
saleHistoryChart.DataSource = saleHistoryDataTable
Exit sub

2 个答案:

答案 0 :(得分:1)

由于社区成员没有提供解决方案,我在运行时添加了该系列,以便我可以使用saleHistoryChart.Series.Clear()并再次设置该系列。比使用直接绑定更多的代码。但这是我能找到的唯一解决方案。

答案 1 :(得分:0)

Dim RadChart1 As New RadChart
Public Sub New()
    InitializeComponent()
    Me.Controls.Add(RadChart1)
Dim connectionString As [String] = "Integrated Security=SSPI;Persist Security Info=False; Initial Catalog=Northwind;Data Source=.\sqlexpress"Dim selectCommand As String = "SELECT CategoryName, SUM(ProductSales) AS TotalSales FROM [Product Sales for 1997] GROUP BY CategoryName"
    Dim dataAdapter As New SqlDataAdapter(selectCommand, connectionString)
    Dim table As New DataTable()
    dataAdapter.Fill(table)
    RadChart1.DataSource = table
    RadChart1.PlotArea.XAxis.DataLabelsColumn = "CategoryName"
    AddHandler RadChart1.DataBound, AddressOf radChart1_DataBound
End Sub
Private Sub radChart1_DataBound(ByVal sender As Object, ByVal e As EventArgs)
    radChart1.Series(0).DataYColumn = "TotalSales"
    ' assign appearance related properties
    radChart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 300
    radChart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.BlueViolet
    RadChart1.PlotArea.Appearance.Dimensions.Margins.Bottom = Telerik.Charting.Styles.Unit.Percentage(20)
    RadChart1.PlotArea.Appearance.Dimensions.Margins.Left = Telerik.Charting.Styles.Unit.Percentage(20)`enter code here`
End Sub