Wire Chart-Control to ViewModel

Topics: Getting Started
Sep 30, 2012 at 2:52 PM

Hi everyone,

I'm a bit lost here atm, because I don't know how I could wire up the Chart - Control of the WPF Toolkit with my ViewModel. Here is what I've got:

        <tool:Chart Title="Column Series Demo" BorderThickness="0" cal:Bind.Model="{Binding}">
            <tool:ColumnSeries DependentValuePath="Value" 
		IndependentValuePath="Key" Name="valueList"    />

I thought that Binding the parent object via Bind.Model would do the trick, but I was wrong. ColumSeries has an ItemSource Property, but... 

I'm sure I'm doing something wrong, but what?

Oct 2, 2012 at 8:16 PM
Edited Oct 2, 2012 at 8:17 PM
<Grid Grid.Column="2" Grid.Row="1" Grid.RowSpan="50" Margin="15,0,0,0" Width="Auto" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <chartingTK:Chart Grid.Column="3" Grid.RowSpan="7" Height="Auto" Width="Auto"
                              HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataContext="{Binding BreakDown}" 
                              HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                              Title="Flight Hours Per Aircraft"
                              LegendTitle="Aircraft Model"                                           
                <chartingTK:PieSeries  Name="pieMakeTime"       
                                       IndependentValueBinding="{Binding AircraftType}" DependentValueBinding="{Binding TotalTime}" TransitionDuration="00:00:00.3000000" AnimationSequence="FirstToLast" IsSelectionEnabled="True">                    

this is a snip of some really old code I used to wire a pieseries the AircraftType is the "Key" in this case which is the wedge of the pie and the TotalTime is the actually size of the wedge.  "BreadDown" was the datasource to actually provide the values between the 2 tables used for this example.  This example isn't Caliburn Specific, it was actually Prism based. 

DataContext won't be a consideration with a solution for CM since you won't have to set the DataContext it will be done for you.. So ItemSource on the actual Series will be set to what ever contains the Data to display while you set the respective In(Dependent)ValueBinding according to your requirements.

As for cal:Bind.Model won't necessarily be needed yet.

Let me know if that helps or if you need further code samples.