Jump to content
Software FX Community

Yet another data binding problem


Rakoo
 Share

Recommended Posts

I am trying to do bind data like below:

  public partial class Chart : Window   {   public class CountryData   {   public string Year { get; set; }   public string Country { get; set; }   public double Value { get; set; }   }   private List<CountryData> countryData;   public Chart()   {   InitializeComponent();   countryData = new List<CountryData>();   countryData.Add(new CountryData { Year = "2004", Country = "USA", Value = 1 });   countryData.Add(new CountryData { Year = "2004", Country = "CAN", Value = 5 });   countryData.Add(new CountryData { Year = "2005", Country = "USA", Value = 3 });   countryData.Add(new CountryData { Year = "2005", Country = "CAN", Value = 15 });   ListTransform lt = new ListTransform();   lt.ColumnPath = "Year";   lt.SeriesPath = "Country";   lt.ValuePath = "Value";   chart1.DataTransforms.Add(lt);   chart1.ItemsSource = countryData;   }

When I execute the code I got following error: "Object reference not set to an instance of an object."

 

System.NullReferenceException was unhandled  Message="Object reference not set to an instance of an object."  Source="ChartFX.WPF"  StackTrace: at ChartFX.WPF.Internal.ClrObjectColumnGetter.a(Type A_0, String A_1, Type& A_2) at ChartFX.WPF.Internal.ClrObjectColumnGetter.a(Type A_0, String A_1) at ChartFX.WPF.Internal.ColumnGetter.Detect(Object obj, Type type, String name, DetectOptions options) at ChartFX.WPF.Internal.ColumnGetter.DetectChildGetter(Object obj, Type type, String name, DetectOptions options) at ChartFX.WPF.Data.ListTransform.a(Object A_0, Type A_1, String A_2, DetectOptions A_3) at ChartFX.WPF.Data.ListTransform.a(IEnumerable A_0, Object& A_1, IEnumerator& A_2) at ChartFX.WPF.Data.ListTransform.ChartFX.WPF.Data.IDataTransform.Transform(IAmbient ambient, IEnumerable enumerable, Boolean hook, NotifyCollectionChangedAction action) at ChartFX.WPF.Internal.DataBindingHelper.a(IAmbient A_0, DataTransformStyles& A_1) at ChartFX.WPF.DataValues.a(DataBindingHelper A_0, Boolean A_1) at ChartFX.WPF.Chart.ay() at ChartFX.WPF.Chart.h() at ChartFX.WPF.Chart.a(Object A_0, RoutedEventArgs A_1) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root) at MS.Internal.LoadedOrUnloadedOperation.DoWork() at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget) at System.Windows.Interop.HwndTarget.OnResize() at System.Windows.Interop.HwndTarget.HandleMessage(Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow) at System.Windows.Window.ShowHelper(Object booleanBox) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at ChartFXforWPF_Demo.App.Main() in C:\Users\mrakowski\Desktop\ChartFXforWPF-Demo\obj\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()  InnerException:

Any ideas where the problem is?

Thanks in advance

Maciej Rakowski

Link to comment
Share on other sites

ListTransform is not the right one to use in this scenario as it expects each one of the elements in the top-level list to be another list.

If what you want is a chart with as many series as years and as many X axis points as countries (or viceversa) you need to use the CrosstabTransform, e.g.

CrosstabTransform crosstab = new CrosstabTransform();crosstab.ColumnPath = "Year";crosstab.RowPath = "Country";crosstab.ValuePath = "Value";chart1.DataTransforms.Add(crosstab);

Regards,

JuanC

Link to comment
Share on other sites

I have next problem. I did CrosstabTransform and it looks ok on Bar chart, but the Pie chart does not have series names over each Pie (the same problem is with for example Pyramid chart). The group names and values are correct. Example: http://img228.imageshack.us/my.php?image=problemny9.jpg . The name of each pie is the name of object type in List provided as ItemsSource.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...