从Array VB.NET获取DevExpress图表系列值

时间:2015-02-19 21:25:36

标签: vb.net charts devexpress

我试图从SQL Table中的Data设置DevExpress Chart Series。 一切都很顺利,只是图表只采用了最后一个系列的最后一个属性 我的代码是:

con.Open() 'it opens SQL Connection
For i = 0 To (CheckedListBoxControl1.CheckedItems.Count - 1) 'list from ListBox        
    Lst.Add(CheckedListBoxControl1.CheckedItems(i).ToString) 'Putting Data in Array List
    Dim Strl As String = String.Format("Select * from VPRogressCumulative where fname like '{0}' and lname like  '{1}' order by id, no, CAST('1.' + date AS datetime)", ComboBox1.Text, Lst(i))

    Dim sqlCom As New SqlCommand(Strl)
    sqlCom.Connection = con
    Dim myDA As SqlDataAdapter = New SqlDataAdapter(sqlCom)
    Dim myDataSet As DataSet = New DataSet()
    myDA.Fill(myDataSet, "VPRogressCumulative")
    ChartControl1.DataSource = myDataSet
    ChartControl1.DataAdapter = myDA

    Dim ser As New Series(Lst(i), ViewType.Line)
    ChartControl1.Series.Add(ser)

    ser.ArgumentDataMember = "VPRogressCumulative.Date"
    ser.ValueDataMembers.AddRange(New String() {"VPRogressCumulative.Cumulative"})
Next
con.Close()

我相信我的问题在于:

Dim ser As New Series(Lst(i), ViewType.Line)
ChartControl1.Series.Add(ser)
ser.ArgumentDataMember = "VPRogressCumulative.Date"
ser.ValueDataMembers.AddRange(New String() {"VPRogressCumulative.Cumulative"})

最后两行给出了相同系列的新属性,而我无法解决此问题。

1 个答案:

答案 0 :(得分:0)

你的问题在这里:

ChartControl1.DataSource = myDataSet
ChartControl1.DataAdapter = myDA

在每个周期的迭代中,您创建新的DataSet并覆盖DataSource中的上一个ChartControl1。您必须使用Series.DataSource代替ChartControl.DataSource。您也可以使用DataTable代替DataSet 这是一个例子:

'Your code:
'Dim myDataSet As DataSet = New DataSet()
'myDA.Fill(myDataSet, "VPRogressCumulative")
'ChartControl1.DataSource = myDataSet
'ChartControl1.DataAdapter = myDA

'Replace with this:
Dim myDataTable As DataTable = New DataTable("VPRogressCumulative")
myDA.Fill(myDataTable)

Dim ser As New Series(Lst(i), ViewType.Line)
ChartControl1.Series.Add(ser)

'Your code.
'ser.ArgumentDataMember = "VPRogressCumulative.Date"
'ser.ValueDataMembers.AddRange(New String() {"VPRogressCumulative.Cumulative"})

'Replace with this:
ser.DataSource = myDataTable
ser.ArgumentDataMember = "Date"
ser.ValueDataMembers.AddRange(New String() {"Cumulative"})