I have come to this problem too, after i have upgraded my application from .NET FRAMEWORK 3.5 to 4.0, suddently the chart class stopped working.
When i called Show() method on form that had the chart with dynamic columnseries, instead of displaying the new window, this error popped up: Object reference not set to an instance of an object.
If i remove the itemsource link to Dictionary, or change the dynamic columnseries to static XAML version, it works though, but this static version is unusable for most users.
anybody has idea how to implement this directly in WPF .NET Framework 4.0? or its bug in wpftoolkit which is targetted to .NET 3.5 ?
public void SetChartData(IDictionary<string, IDictionary<string, double>> prod, String title, String labelAxis)
{
chart.Title = title;
LinearAxis ca = new LinearAxis();
ca.Orientation = AxisOrientation.Y;
ca.Minimum = 0;
chart.Axes.Add(ca);
foreach (KeyValuePair<string, IDictionary<string, double>> kvp in prod)
{
ColumnSeries cser = new ColumnSeries();
cser.Title = kvp.Key;
cser.DependentValueBinding = new Binding("Value");
cser.IndependentValueBinding = new Binding("Key");
cser.ItemsSource = kvp.Value;
chart.Series.Add(cser);
}
}
i have found one possible workaround:
- create new WPF project library for ex. MyChart, create a class that will return WPF Window with chart inside.
- setup and compile the chart library project as .NET Framework 3.5 (client)
- calling MyChartClass.Show(); inside main program .NET Framework 4.0 will display the chart properly