nabils Posted April 16, 2008 Report Posted April 16, 2008 I am trying to bind to an IEnumerable<T> using chart.ItemsSource = data where data is the IEnumerable<T>. The xaml I am using is: <cfx:Chart Gallery="Pie" Name="chart"> <cfx:SeriesAttributes BindingPath="{Binding Path=Value}"/> </cfx:Chart> As soon as the chart.ItemsSource = data line is executed I get a recurring exception which hangs the whole application (see below). What am I doing wrong? Thanks System.NullReferenceException: Object reference not set to an instance of an object. at k.a(Object A_0, Type A_1, String A_2) at at.a(Object A_0, Object A_1, Type A_2, Int32 A_3) at cb.a(Object A_0, Object A_1, Type A_2, Int32 A_3) at ChartFX.WPF.DataValues.a(IEnumerable A_0, Int32 A_1, Int32 A_2, NotifyCollectionChangedAction A_3, IIndexedCollection`1 A_4, ah A_5) at ChartFX.WPF.DataValues.a(IEnumerable A_0, Int32 A_1, Int32 A_2, NotifyCollectionChangedAction A_3, ah A_4) at ChartFX.WPF.DataValues.a(ah A_0) at ChartFX.WPF.Chart.at() at ChartFX.WPF.Chart.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Border.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Control.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Border.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Control.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Border.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Control.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Border.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
JuanC Posted April 16, 2008 Report Posted April 16, 2008 Can you tell us more about your data? e.g. what is the data type for the "Value" property? Is there anything special about the values being used? Can you duplicate this error on a standalone project? Regards, JuanC
nabils Posted April 17, 2008 Author Report Posted April 17, 2008 Thank you for your quick response. I was passing in incorrect data. Do you have a sample for the crosstabtransform? Thanks
JuanC Posted April 17, 2008 Report Posted April 17, 2008 xmlns:cfxData="clr-namespace:ChartFX.WPF.Data;assembly=ChartFX.WPF.Data" <Page.Resources> <XmlDataProvider x:Key="myXmlData"> <x:XData> <Elems xmlns=""> <Elem Product="CocaCola" Image="pack://siteoforigin:,,,/Img/CocaCola.png" Month="Jan" Sales="12"/> <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Jan" Sales="10"/> <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Jan" Sales="1"/> <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Feb" Sales="8"/> <Elem Product="CocaCola" Image="pack://siteoforigin:,,,/Img/CocaCola.png" Month="Feb" Sales="14"/> <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Mar" Sales="9"/> <Elem Product="CocaCola" Image="pack://siteoforigin:,,,/Img/CocaCola.png" Month="Mar" Sales="13"/> <Elem Product="Sprite" Image="pack://siteoforigin:,,,/Img/Sprite.png" Month="Mar" Sales="5"/> </Elems> </x:XData> </XmlDataProvider> <DataTemplate x:Key="productTemplate"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding XPath=@Image}" Width="24" Height="24"/> <TextBlock Text="{Binding XPath=@Product}" Margin="2,0" VerticalAlignment="Center"/> </StackPanel> </DataTemplate></Page.Resources><cfx:Chart Gallery="Bar" x:Name="chart1"> <cfx:Chart.ItemsSource> <Binding Source="{StaticResource myXmlData}" XPath="Elems/Elem" /> </cfx:Chart.ItemsSource> <cfx:Chart.DataTransforms> <cfxData:CrosstabTransform RowPath="@Month" ColumnPath="@Product" ValuePath="@Sales" Sorted="true"/> </cfx:Chart.DataTransforms> <cfx:Chart.AllSeries> <cfx:AllSeriesAttributes ContentTemplate="{Binding Source={StaticResource productTemplate}}"/> </cfx:Chart.AllSeries></cfx:Chart>In this sample we are using the image in the data as part of the series content which will be shown in both tooltips and in the legendbox. Regards, JuanC
Recommended Posts
Archived
This topic is now archived and is closed to further replies.