Binding X / Y in ScatterSeriesDescriptor

1 Answer 212 Views
ChartView
Sandra
Top achievements
Rank 1
Iron
Sandra asked on 19 May 2021, 08:59 AM

Hi,

I have a RadCartesianChart with a ScatterSeriesDescriptor.

My ViewModel of the data points do not have any values that I can bind directly. Instead, I want to bind to properties within another class.

 

Example:

 Public Class PointViewModel

 Public Property MyValueInX As ValueContainer

 Public Property MyValueInY As ValueContainer

End Class

 

Public Class ValueContainer

 Public Property ValueForDiagram As Double

End Class

 

When I try to bind ValueForDiagram I get a System.ArgumentException: "Could not find property 'MyValueInX .ValueForDiagram ' for type 'TelerikTestProjekt.ViewModel.PointViewModel'".


My XAML:

            <telerik:ScatterSeriesDescriptor ItemsSourcePath="Points" XValuePath="MyValueInX.ValueForDiagram" YValuePath="MyValueInY.ValueForDiagram ">

Is there any way I can set this binding?

Best Regards

Sandra

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 21 May 2021, 10:14 AM

Hello Sandra,

The X/YValueBinding properties of the scatter series and the X/YValuePath properties of the descriptor work with the PropertyNameDataPointBinding class to provide the property definition to the chart and later get the corresponding values from the model. The PropertyNameDataPointBinding expects a string value which represents the property name that should be used from the data point's model. However, this type of binding doesn't support property chains like the one you need (example: MyValueInX .ValueForDiagram). 

In this situation, you can use the GenericDataPointBinding class instead of PropertyNameDataPointBinding. To do so, you should use code-behind. With the SeriesProvider, you can do this by using the SeriesCreated event. You can get the series instance from the event arguments and set the XValueBinding and YValueBinding properties. 

<telerik:ScatterSeriesDescriptor ItemsSourcePath="Points">

Private Sub ChartSeriesProvider_SeriesCreated(ByVal sender As Object, ByVal e As ChartSeriesCreatedEventArgs)
    Dim series = CType(e.Series, ScatterSeries)
    series.XValueBinding = New GenericDataPointBinding(Of PointViewModel, Double)() With {
        .ValueSelector = Function(x) x.MyValueInX.ValueForDiagram
    }
    series.YValueBinding = New GenericDataPointBinding(Of PointViewModel, Double)() With {
        .ValueSelector = Function(x) x.MyValueInY.ValueForDiagram
    }
End Sub

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Sandra
Top achievements
Rank 1
Iron
commented on 26 May 2021, 07:21 AM

Hello Martin, Thanks a lot!
Tags
ChartView
Asked by
Sandra
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or