Mads Mobæk
Mads Mobæk

Reputation: 35970

Bind Dictionary to Chart

I'm new to Silverlight and I am trying to display the contents of a Dictionary in a Graph:

In codebehind:

ChartData = new Dictionary<DateTime, double> {{DateTime.Now, 10}, 
      {DateTime.Now, 20}, {DateTime.Now, 15}};

And in the silverlight XAML:

<toolkit:Chart HorizontalAlignment="Left" Margin="113,168,0,0" Name="chart1" 
   Title="Chart Title" VerticalAlignment="Top">
    <toolkit:LineSeries ItemsSource="{Binding Path=ChartData}"  
          DependentValuePath="Key" IndependentValuePath="Value">
    </toolkit:LineSeries>
</toolkit:Chart>

But this gives "No suitable axis is availible for plotting the dependent value". Suggestions?

Upvotes: 1

Views: 1335

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189505

Try this data set:-

ChartData = new Dictionary<DateTime, double>() { 
  { DateTime.Now.AddDays(-1), 10 }, 
  { DateTime.Now, 20 },
  { DateTime.Now.AddDays(1), 15 }
};

(I'm surprise your line of code even worked, since it would attempt to add multiple keys with the same value into the dictionary).

Then change your Xaml:-

<toolkit:LineSeries ItemsSource="{Binding Path=ChartData}"    
      DependentValuePath="Value" IndependentValuePath="Key">

Its would be highly unusual to use a date as a DependentValue, in fact I can't think of a scenario where a DependentValue would anything other than numeric.

Upvotes: 2

Related Questions