从数组中获取 DevExpress 图表系列值 VB.NET

Getting DevExpress Chart Series Values From Array VB.NET

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

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"})

最后两行为同一系列提供了我无法解决问题的新属性。

您的问题在这里:

ChartControl1.DataSource = myDataSet
ChartControl1.DataAdapter = myDA

在循环的每次迭代中,您都在创建新的 DataSet,它会覆盖 ChartControl1 中的先前 DataSource。您必须使用 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"})