views:

617

answers:

0

I am working with a simple lineseries chart in Silverlight 3 with VB.net and am running into an issue binding the chart to an observablecollection. The chart is going to be used to display changes in BMI data over time for a weight loss application. I have created a simple class that contains the BMI value for the user and the date the BMI was recorded. I then created an observablecollection of this BMI Data class and populate the collection with data that I pull from my database. However, when I try to run the application I am getting an error stating that no suitble axis is available for plotting the dependent value. According to all of the documentation that I've read, the following code should work.

XAML

    <Grid x:Name="LayoutRoot" Background="White">
    <chartingToolkit:Chart HorizontalAlignment="Left" Name="Chart1" Title="Chart Title" VerticalAlignment="Top" Width="400" Height="300">
            <chartingToolkit:LineSeries ItemsSource="{Binding}" DependentValueBinding="{Binding BMI}" IndependentValueBinding="{Binding BMIDate}" Title="BMI"/>
    </chartingToolkit:Chart>
</Grid>

Here is the vb.net codebehind that populates the collection.

Dim dataCollection As New ObservableCollection(Of BMIData)

Public Sub New()
    InitializeComponent()

    Dim bmiData1 As New BMIData
    bmiData1.BMIDate = "03/23/2010"
    bmiData1.BMI = 30.86
    dataCollection.Add(bmiData1)

    Dim bmiData2 As New BMIData
    bmiData2.BMIDate = "03/25/2010"
    bmiData2.BMI = 20.37
    dataCollection.Add(bmiData2)

    Dim bmiData3 As New BMIData
    bmiData3.BMIDate = "03/31/2010"
    bmiData3.BMI = 15.86
    dataCollection.Add(bmiData3)

    Dim bmiData4 As New BMIData
    bmiData4.BMIDate = "04/01/2010"
    bmiData4.BMI = 10.75
    dataCollection.Add(bmiData4)

    Chart1.DataContext = dataCollection
End Sub

What am I missing to tell the chart what data is supposed to go on each axis? If I use a dictionary instead of an observablecollection the chart has no problem rendering. However, I would like to eventually set up a timer that adds another data point to the collection every XX miliseconds in order to make the rendering of the chart a bit more dramatic as the data points are "animated" as they plot over time and I need to use an observablecollection in order to achieve that result.