Chart Crash

4 posts, 1 answers
  1. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 06 Nov 2009 Link to this post

    Hi, I'm currently trying the charting component in my winform application. (version 2009.1.9.316)
    Now I've got just a treeview and a chart component on my winform.
    when I click on a treenode the chart view is loaded with the data, everything works fine.
    now as long as my treeview isn't reloaded the chart loads the data, but when in my main form is triggered to reload the treeview and I click a treenode, my program crashes. with the following exception:

    general exception:    at Telerik.Charting.Chart.GetException(RenderEngine renderEngine, Exception ex)
       at Telerik.Charting.Chart.GetImage(Int32 width, Int32 height)
       at Telerik.Charting.Chart.GetImage()
       at Telerik.WinControls.UI.RadChart.GetImage()
       at Telerik.WinControls.UI.RadChart.OnPaint(PaintEventArgs e)
      
    in the innerexception I'm reading system.nullreferenceexception
       at Telerik.Charting.ChartSeriesItem.set_Parent(ChartSeries value)
       at Telerik.Charting.ChartSeriesItem.Clone()
       at Telerik.Charting.ChartSeries.CopyItems(ChartSeries originalSeries)
       at Telerik.Charting.ChartSeries.CloneSeries()
       at Telerik.Charting.RenderEngine.InitializeChartElements()
       at Telerik.Charting.Chart.GetImage(Int32 width, Int32 height)

    how is this possible? I didn't found anything bizar in my code. I added a try catch around the code that fills the chart, but the error isn't triggered here, but in my main try catch of my program.

    my code:

    public partial class HistoricData : Form 
        { 
            public IOController TheIO { getset; } 
     
            public HistoricData() 
            { 
                InitializeComponent(); 
                 
            } 
     
            public void FillData(List<ChartHistoric> days, string title) 
            { 
                try 
                { 
                    rchrtHistoricData.DataSource = days; 
                    rchrtHistoricData.ChartTitle.TextBlock.Text = title; 
                    rchrtHistoricData.PlotArea.XAxis.DataLabelsColumn = "Month"
                    rchrtHistoricData.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = -45; 
                    rchrtHistoricData.DataBind();     
                }catch(Exception ex) 
                { 
                    Logging.Log.LogMessageToFile("HistoricData.cs -> FillData(List<ChartHistoric> days): " + ex.Message + ex.StackTrace); 
                } 
                 
            } 
     
            public void FillTreeView(TreeNode overview) 
            { 
                trvMonths.Nodes.Clear(); 
                trvMonths.Nodes.Add(overview); 
            } 
     
            public void ClearChart() 
            { 
                rchrtHistoricData.DataSource = new List<ChartHistoric>();  
                rchrtHistoricData.DataBind(); 
            } 
     
            private void trvMonths_AfterSelect(object sender, TreeViewEventArgs e) 
            { 
                if(trvMonths.SelectedNode == nullreturn
     
                //ClearChart(); 
     
                //get the selected historic data for this month or whole year. 
                //data for the whole year 
                if(trvMonths.SelectedNode.Tag.Equals("1")) 
                { 
                    FillData(TheIO.GetDataChartHistoricYear(), "Month view"); 
                } 
     
                if(trvMonths.SelectedNode.Tag.Equals("2")) 
                { 
                    FillData(TheIO.GetDataChartHistoricMonth(trvMonths.SelectedNode.Text), "Week view"); 
                } 
            } 
        }



    The function TheIO.GetDataChartHistoricMonth or TheIO.GetDataChartHIstoricYear are returning a list of ChartHistoric

    public class ChartHistoric 
        { 
            public ChartHistoric(string _month, int _days) 
            { 
                month = _month; 
                days = _days; 
            } 
            private string month; 
            public string Month 
            { 
                get { return month; } 
                set { month = value; } 
            } 
            private int days; 
            public int Days 
            { 
                get { return days; } 
                set { days = value; } 
            } 
        } 

    Thanks a lot

  2. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 06 Nov 2009 Link to this post

    Okay
    I think I know where the crash happens.
    When in my main form a treenode is triggered, the historicdata view is being reloaded. So the treeview on that form is reloaded and I'm clearing the chart from his datasource. Now I think that is the problem, I clear the datasource badly.

    public void ClearChart() 
            { 
                rchrtHistoricData.DataSource = new List<ChartHistoric>(); 
                rchrtHistoricData.DataBind(); 
            } 

    What is the best way to clear the datasource?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 11 Nov 2009 Link to this post

    Hi gerbrand,

    To clear the data in the RadChart use:
    this.radChart1.Clear();
    this.radChart1.Refresh();

    Let me know if you experience further issues with your scenario. Any sample application that we can debug would be helpful.

    Sincerely yours,
    Evtim
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 13 Nov 2009 Link to this post

    Before you posted the answer, I had already found this in the documentation after reading it a little bit better.

    Since then I didn't had any issues anymore.

    Thanks a lot
Back to Top