How to redraw chart?

6 posts, 1 answers
  1. hyojung kwon
    hyojung kwon avatar
    6 posts
    Member since:
    Jan 2010

    Posted 22 Jun 2010 Link to this post

    Hello,

    In my application I draw LineSeries chart using WCF service.
    Chart is drawn, once page is loaded for the first time and when user click refresh button, it gets new data using WCF service then is supposed to be redrawn.
    However, when chart is redrawn by refresh button, LineSeries chart draws over old chart without clearing old chart.

    I used following code to refresh chart.

           void server_GetGraphDataCompleted(object sender, GetGraphDataCompletedEventArgs e)
            {
                RadChart1.ItemsSource = null;
                List<GraphEntity> result = e.Result;
                RadChart1.ItemsSource = result;
            }

    Whenever user click refresh button, chart is created over old one.

    Can you tell me what I did wrong?

    Thanks in advance
    Kwon

  2. Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 25 Jun 2010 Link to this post

    Hello hyojung kwon,

    You are binding the chart correctly. Most probably the data returned in the second call to the service contains the old data as well and the chart correctly plots both series.

    Best wishes,
    Vladimir Milev
    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. hyojung kwon
    hyojung kwon avatar
    6 posts
    Member since:
    Jan 2010

    Posted 27 Jun 2010 Link to this post

    I checked my code but data returned from service has same counts and same data.
    Following is my code in silverlight behind code.

    private ServiceReference.ServiceClient server;

    public GraphDemo()
            {
                InitializeComponent();
             
                server = new ServiceReference.ServiceClient();
                server.GetGraphDataCompleted += new EventHandler<GetGraphDataCompletedEventArgs>(server_GetGraphDataCompleted);

                FillChartData();
            }

     private void FillChartData()
            {
                    SeriesMapping sm2 = new SeriesMapping();
                    sm2.SeriesDefinition = new LineSeriesDefinition();
                    sm2.LegendLabel = "SpO2";

                    ItemMapping im3 = new ItemMapping("SpO2Value", DataPointMember.YValue);
                    ItemMapping im4 = new ItemMapping("ColumnTimeForXCategory", DataPointMember.XCategory);
                    sm2.ItemMappings.Add(im3);
                    sm2.ItemMappings.Add(im4);

                    RadChart1.SeriesMappings.Add(sm2);
                    
                    server.GetGraphDataAsync();
    }

    void server_GetGraphDataCompleted(object sender, GetGraphDataCompletedEventArgs e)
            {
                RadChart1.ItemsSource = null;
                List<GraphEntity> result = e.Result; // returns same number of data from service
                RadChart1.ItemsSource = result;
            }


    Is there any doubtable code up there?

    Thanks in advance.
    Kwon

  4. Answer
    Nikolay
    Admin
    Nikolay avatar
    397 posts

    Posted 30 Jun 2010 Link to this post

    Hello hyojung kwon,

    It appears that the issue is related to what happens when clicking the Refresh button. In order to clear the older chart you need to clear the SeriesMappings and call FillChartData() again, as shown below :

    private void RefreshButton_Click(object sender, RoutedEventArgs e)
           {
               RadChart1.SeriesMappings.Clear();
               this.FillChartData();
           }

    Please, let us know if this works on your side as well.

    Kind regards,
    Nikolay
    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
  5. hyojung kwon
    hyojung kwon avatar
    6 posts
    Member since:
    Jan 2010

    Posted 30 Jun 2010 Link to this post

    Hello Nikolay

    It is working well for me.
    Thank you so much.

    Regards
    Kwon
  6. Niclas Junsved
    Niclas Junsved avatar
    10 posts
    Member since:
    Dec 2009

    Posted 04 Aug 2010 Link to this post

    Hi!

    How do I achieve "clear" as below in Q2 2010 version?

     

    radChart.SeriesMappings.Clear();

     


    Regards

    Niclas

Back to Top