NullReferenceException on deferred load of series

8 posts, 0 answers
  1. Alex
    Alex avatar
    13 posts
    Member since:
    Jun 2011

    Posted 01 Jun 2011 Link to this post

    This sample raises NullReferenceException in tha AxisX.CalculateItemRange method

    View:
    <Window.Resources>

            <DataTemplate x:Key="measTemplate">
                <telerik:RadChart ItemsSource="{Binding ChartData, Mode=OneWay}" >
                    <telerik:RadChart.DefaultView>
                        <telerik:ChartDefaultView>
                            <telerik:ChartDefaultView.ChartLegend>
                                <telerik:ChartLegend UseAutoGeneratedItems="True" Header=" " x:Name="chartLegend">
                                </telerik:ChartLegend>
                            </telerik:ChartDefaultView.ChartLegend>
                            <telerik:ChartDefaultView.ChartArea>
                                <telerik:ChartArea LegendName="chartLegend" EnableAnimations="True">
                                    <telerik:ChartArea.AxisX>
                                        <telerik:AxisX />
                                    </telerik:ChartArea.AxisX>
                                    <telerik:ChartArea.AxisY>
                                        <telerik:AxisY DefaultLabelFormat="F2"/>
                                    </telerik:ChartArea.AxisY>
                                    <telerik:ChartArea.AdditionalYAxes>
                                        <telerik:AxisY AxisName="Secondary" DefaultLabelFormat="F2"/>
                                    </telerik:ChartArea.AdditionalYAxes>
                                </telerik:ChartArea>
                            </telerik:ChartDefaultView.ChartArea>
                        </telerik:ChartDefaultView>
                    </telerik:RadChart.DefaultView>
                    <telerik:RadChart.SeriesMappings>
                        <telerik:SeriesMapping LegendLabel="R">
                            <telerik:SeriesMapping.SeriesDefinition>
                                <telerik:LineSeriesDefinition ShowItemLabels="False" AxisName="Secondary"/>
                            </telerik:SeriesMapping.SeriesDefinition>
                            <telerik:ItemMapping FieldName="ValueY" DataPointMember="YValue"/>
                            <telerik:ItemMapping FieldName="ValueX" DataPointMember="XValue"/>
                        </telerik:SeriesMapping>
                        <telerik:SeriesMapping LegendLabel="C">
                            <telerik:SeriesMapping.SeriesDefinition>
                                <telerik:LineSeriesDefinition ShowItemLabels="False"/>
                            </telerik:SeriesMapping.SeriesDefinition>
                            <telerik:ItemMapping FieldName="ValueY1" DataPointMember="YValue"/>
                            <telerik:ItemMapping FieldName="ValueX" DataPointMember="XValue"/>
                        </telerik:SeriesMapping>
                    </telerik:RadChart.SeriesMappings>
                </telerik:RadChart>
            </DataTemplate>
        </Window.Resources>
        <DockPanel>
            <ItemsControl ItemsSource="{Binding Context.Charts}" ItemTemplate="{StaticResource measTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Columns="1" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </DockPanel>

    View CodeBehind 
    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                this.Context = new Context();
                this.DataContext = this;
            }
     
     
            public Context Context { get; set; }
        }
     
     
        public class Context
        {
            public Context()
            {
                this.Charts = new ObservableCollection<ChartDataHolder>();
                for (int i = 0; i < 2; i++)
                {
                    this.Charts.Add(new ChartDataHolder());
                }
            }
     
     
            public ObservableCollection<ChartDataHolder> Charts { get; private set; }
        }


    ViewModel:
    public class ChartDataHolder
        {
            private readonly BackgroundWorker worker = new BackgroundWorker();
     
            public ChartDataHolder()
            {
    this.ChartData = new ObservableCollection<ChartDataItem>();
                worker.DoWork += this.worker_DoWork;
                this.worker.RunWorkerAsync();
     
            }
     
            void worker_DoWork(object sender, DoWorkEventArgs e)
            {
                Thread.Sleep(TimeSpan.FromSeconds(1)); //!! Without it it works fine
                while (true)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        Application.Current.Dispatcher.BeginInvoke(new Action(this.ProcessResult), null);
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(5));
                }
            }
     
            private void ProcessResult()
            {
                this.ChartData.Clear();
                for (int i = 0; i < 20; i++)
                {
                    this.ChartData.Add(new ChartDataItem() { ValueX = DateTime.Now.Second + i, ValueY = DateTime.Now.Second + i });
                }
            }
     
            public ObservableCollection<ChartDataItem> ChartData { get; private set; }
        }
  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 06 Jun 2011 Link to this post

    Hi Alex,

    You can find attached a small example, based on your code. It works fine at my end. Please, give it a try and let us know if it works correctly for you. Make sure you use the latest version -- currently Q1 2011 SP1.

    Kind regards,
    Ves
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alex
    Alex avatar
    13 posts
    Member since:
    Jun 2011

    Posted 07 Jun 2011 Link to this post

    Hi.
    Thanks for the reply, but I have this problem in your sample too.
    WPF 4.0 (4.0.30319)
    Telerik.Windows.Controls.Charting.dll 2011.1.516.40

    p.s. I temporary solve it using converter and usercontrol to manualy create new instance of the chart for every data template item. Without it I get this exception or all the charts have the same axis intervals according the last data items.
  5. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 08 Jun 2011 Link to this post

    Hi Alex,

    Thank you for the additional details. We were able to reproduce the problem locally. It is now logged and you can track it in our Public Issue Tracking System -- link. Please, use the workaround you have found for the time being.

    I have updated your Telerik points for bringing this to our attention.

    Kind regards,
    Ves
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Alex
    Alex avatar
    13 posts
    Member since:
    Jun 2011

    Posted 08 Jun 2011 Link to this post

    Hi. 
    I found a new problem, now with the Y axis.
    This code generates two charts with the same Y axises, but the Y axis at the first chart should have different values 

    View:
     
     <Window.Resources>
                <DataTemplate x:Key="measTemplate">
                    <telerik:RadChart ItemsSource="{Binding ChartData, Mode=OneWay}" >
                        <telerik:RadChart.DefaultView>
                            <telerik:ChartDefaultView>
                                <telerik:ChartDefaultView.ChartLegend>
                                    <telerik:ChartLegend UseAutoGeneratedItems="True" Header=" " x:Name="chartLegend">
                                    </telerik:ChartLegend>
                                </telerik:ChartDefaultView.ChartLegend>
                                <telerik:ChartDefaultView.ChartArea>
                                    <telerik:ChartArea LegendName="chartLegend" EnableAnimations="True">
                                        <telerik:ChartArea.AxisX>
                                            <telerik:AxisX />
                                        </telerik:ChartArea.AxisX>
                                        <telerik:ChartArea.AxisY>
                                            <telerik:AxisY DefaultLabelFormat="F2"/>
                                        </telerik:ChartArea.AxisY>
                                    </telerik:ChartArea>
                                </telerik:ChartDefaultView.ChartArea>
                            </telerik:ChartDefaultView>
                        </telerik:RadChart.DefaultView>
                        <telerik:RadChart.SeriesMappings>
                            <telerik:SeriesMapping LegendLabel="C">
                                <telerik:SeriesMapping.SeriesDefinition>
                                    <telerik:LineSeriesDefinition ShowItemLabels="False"/>
                                </telerik:SeriesMapping.SeriesDefinition>
                                <telerik:ItemMapping FieldName="ValueY" DataPointMember="YValue"/>
                                <telerik:ItemMapping FieldName="ValueX" DataPointMember="XValue"/>
                            </telerik:SeriesMapping>
                        </telerik:RadChart.SeriesMappings>
                    </telerik:RadChart>
                </DataTemplate>
            </Window.Resources>
            <DockPanel>
                <ItemsControl ItemsSource="{Binding Context.Charts}" ItemTemplate="{StaticResource measTemplate}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Columns="1" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </DockPanel>

    Codebehind
     
        public partial class XAxisTest : Window
        {
            public XAxisTest()
            {
                InitializeComponent();
                InitializeComponent();
                this.Context = new Context();
                this.DataContext = this;
            }
     
            public Context Context { get; set; }
        }
     
        public class Context
        {
            public Context()
            {
                this.Charts = new ObservableCollection<ChartDataHolder>();
                this.Charts.Add(new ChartDataHolder(1));
                this.Charts.Add(new ChartDataHolder(100));
            }
     
     
            public ObservableCollection<ChartDataHolder> Charts { get; private set; }
        }
     
        public class ChartDataHolder
        {
            public ChartDataHolder(double delta)
            {
                this.ChartData = new ObservableCollection<ChartDataItem>();
                for (int i = 0; i < 20; i++)
                {
                    this.ChartData.Add(new ChartDataItem() { ValueX = DateTime.Now.Second + i, ValueY = DateTime.Now.Second * delta + i });
                }
            }
     
            public ObservableCollection<ChartDataItem> ChartData { get; private set; }
        }
     
        public class ChartDataItem
        {
            public int ValueX { get; set; }
            public double ValueY { get; set; }
        }

  7. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 13 Jun 2011 Link to this post

    Hello Alex,

    Indeed, the problem exists in WPF 3.5 only. You can find it discussed in details along with a possible workaround in this forum thread.

    Regards,
    Ves
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Alex
    Alex avatar
    13 posts
    Member since:
    Jun 2011

    Posted 13 Jun 2011 Link to this post

    Hi, thanks for the link, but as I already wrote, I use WPF 4.0 (4.0.30319) so this problem exists not in WPF 3.5 only.
  9. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 14 Jun 2011 Link to this post

    Hi Alex,

    I am sorry for omitting this. I can confirm this is a bug in the control. You can track it here.  I have updated your Telerik points again.

    Best regards,
    Ves
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready