I'm having issues trying to bind my RadCartesianChart to different objects. I'm Trying to create a simple bar graph that shows the loan amount for each of the 3 objects. I'm using an MVVM pattern and the DataContext does have my 3 objects (Current, Proposed, PayDown) available. I'd like to set up the bindings in XAML. Here's what I currently have:
<telerikChart:RadCartesianChart Width="500" >
<chartView:BarSeries ItemsSource="{Binding CurrentLoan}" ValueBinding="LoanAmount" CategoryBinding="Name"/>
<chartView:BarSeries ItemsSource="{Binding Proposed}" ValueBinding="LoanAmount" CategoryBinding="Name"/>
<chartView:BarSeries ItemsSource="{Binding PayDown}" ValueBinding="LoanAmount" CategoryBinding="Name"/>
<telerikChart:RadCartesianChart.HorizontalAxis>
<chartView:CategoricalAxis/>
</telerikChart:RadCartesianChart.HorizontalAxis>
<telerikChart:RadCartesianChart.VerticalAxis>
<chartView:LinearAxis/>
</telerikChart:RadCartesianChart.VerticalAxis>
</telerikChart:RadCartesianChart>
After Loading the app it displays "No Data Series" added. If I throw the objects to a list and set the items source for each BarSeries to an object in that list it works no problem. Any Ideas on what I'm droing wrong? Thanks!
The BarSeries.ItemsSource property is of type IEnumerable (see here). This is why it works when you throw your items into a list. You don't show your viewmodel, but it looks like it has your three business-model objects exposed (Current, Proposed, PayDown), and, one assumes, these do not implement IEnumerable.
You probably want to do something like what's in the example here, setting the DataPoints property of the BarSeries with three CategoricalDataPoint items whose Values are bound to the three objects in your viewmodel.
Alternatively, you could put the three viewmodel properties into a CompositeCollection in xaml as the ItemsSource.