I'm using WPF Toolkit
extension to show a Column Graph that takes the data from a Dictionary<string,ulong>
(where the strings are the X-values and the ulong the Y ones). This is the declaration of the XAML
<chartingToolkit:Chart x:Name="Chart" HorizontalAlignment="Left" Margin="10,10,0,0" Title="Chart Title" VerticalAlignment="Top" Height="560" Width="1000">
<chartingToolkit:ColumnSeries x:Name="myGraph" DependentValuePath="Key" IndependentValuePath="Value" ItemsSource="{Binding}"/>
</chartingToolkit:Chart>
And I have an object that construct a Dictionary <string,ulong>
so, I declared the global variable
private Dictionary<string,ulong> myDictionary;
to store the data from my object and bind it with the chart as follows
this.myDictionary = myObject.objectDictionary;
myGraph.Title = "My Title";
myGraph.ItemsSource = this.myDictionary;
But I get the following exception:
Object reference not set to an instance of an object.
So, is there I'm doing wrong with the binding?
Regards
Ok, I found the error on my program. Instead of using ItemsSource
, I used myGraph.DataContext
defining the IndependentValuePath
and DependentValuePath
properly.
this.myDictionary = myObject.objectDictionary;
myGraph.DataContext = this.myDictionary;
myGraph.IndependentValuePath = "Key";
myGraph.DependentValuePath = "Value";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.