开发者

Bind Dictionary to Chart

开发者 https://www.devze.com 2023-01-05 19:59 出处:网络
I\'m new to Silverlight and I am trying to display the contents of a Dictionary in a Graph: In codebehind:

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消