We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Proper way to bind multiple series from SAME datasource

How should I bind to one Context to a table that has 2 fields that I would like to plot as series?

I see that CartDataModel.YNames is an array but all the examples just use one member



Do I create two identical ChartDataBind Models like this:
        Dim Model1 As New ChartDataBindModel(Main.Context.NmsSummaries.Local.ToBindingList)
        Model1.XName = "TheDate"

        Model1.YNames = New String() {"Val1"}  ' why is this a array??
        Dim Series1 As New ChartSeries("Val1", ChartSeriesType.Line)
        Series1.Text = Series1.Name
        Series1.SeriesModel = Model1
        CC1.Series.Add(Series1)


        Dim Model2 As New ChartDataBindModel(Main.Context.NmsSummaries.Local.ToBindingList)
        Model2.XName = "TheDate"

        Model1.YNames = New String() {"Val2"}
        Dim Series2 As New ChartSeries("Val2", ChartSeriesType.Line)
        Series2.Text = Series2.Name
        Series2.SeriesModel = Model2
        CC1.Series.Add(Series1)


Or can I reuse the model somehow with  something like this that uses an array of YNames?

      Dim Model1 As New ChartDataBindModel(Main.Context.NmsSummaries.Local.ToBindingList)
        Model1.XName = "TheDate"

        Model1.YNames = New String() {"Val1", "Val2"} ' 
        Dim Series1 As New ChartSeries("Val1", ChartSeriesType.Line)
        Series1.Text = Series1.Name
        Series1.SeriesModel = Model1
        Series1.YVAL = Model1.YNames(0) ' - does not work
        CC1.Series.Add(Series1)


        Dim Series2 As New ChartSeries("Val2", ChartSeriesType.Line)
        Series2.Text = Series2.Name
        Series2.SeriesModel = Model1
        Series1.YVAL = Model1.YNames(1) ' - does not work
        CC1.Series.Add(Series1)



1 Reply

AT Anandaraj T Syncfusion Team June 5, 2013 07:14 PM UTC

Hi Dennis,

Thanks for using Syncfusion products.

The property "YNames" of ChartDataBindModel object is used to bind data in columns of the table to the y values of chart series points. This property is defined as an array because chart types like range area chart and heat map chart requires a minimum of two y values to plot and they need one column data for each y value. Hence, the "YNames" property cannot be used to bind a ChartDataBindModel  object with more than one series.

Please refer the following code snippet to bind a table data to more than one series:
[VB]

Function ReturnDataBindModel (ByVal ColumnName As String) As ChartDataBindModel

Dim Model1 As New ChartDataBindModel(Main.Context.NmsSummaries.Local.ToBindingList)

Model1.XName=”TheDate”

Model1.YNames=New String() {ColumnName}

Return Model1

End Sub

 

Sub Main()

Dim Series1 As New ChartSeries(“Val1”, ChartSeriesType.Line)

Series1.Text=Series1.Name

Series1.SeriesModel=ReturnDataBindModel(“Val1”)

CC1.Series.Add(Series1)

 

Dim Series2 As New ChartSeries(“Val2”, ChartSeriesType.Line)

Series2.Text=Series2.Name

Series2.SeriesModel=ReturnDataBindModel(“Val2”)

CC2.Series.Add(Series2)

End Sub

The ChartDataBindModel object can be reused as in the above code snippet to bind a table data with multiple series or we have to use one ChartDataBindModel  object for each series.

Please let us know if you have any concerns.

Regards,

Anandaraj

 



Loader.
Live Chat Icon For mobile
Up arrow icon