Refresh (or invalidate?) SfChart

Hello,
is it possible to force a redraw of a sfchart?

In one application I have a itemsource that is not an observable collection (lets say a standard list for now) therefore it does notify changes.
After I create the chart I load data from a database in the background. I would like to tell the chart to update once I finish loading from the background task.

One way to do it is to create the series with a null itemsource and then once I finish loading set the itemsource. I do not like this idea because it does not allows me to to refresh the chart every 10% of the data load for example.

Is there a method for me to call chart.Refresh() or something similar?

Thanks!

7 Replies

MK Muneesh Kumar G Syncfusion Team April 12, 2018 01:04 PM UTC

Hi Juliano 
 
Thanks for using Syncfusion products.  
 
We can able to achieve your requirement by calling UpdateArea method in SfChart as follows.  
 
Code snippet [C#]  
 
 
MethodInfo info = chart.GetType().GetMethod("UpdateArea", 
                                BindingFlags.NonPublic | BindingFlags.Instance, 
                                null, 
                                new Type[] { typeof(bool) }, 
                                null); 
 
info?.Invoke(chart, new object[] { true }); 
 
 
Please let us know if you have any queries.  
 
Thanks, 
Muneesh Kumar G. 



JF Juliano Franz May 3, 2018 05:47 PM UTC

Hi Muneesh,
sorry for this long delay. I got sucked into other projects for a while =]

Your solution did worked for me. Here is what a I have:
  • A async TCP client that receives data updates and stores into a List<DataType>
  • A number of series that have the ItemSource set to that list
  • A DispatcherTimer that calls the following refresh method every n seconds (could not figure out how to add code)

        public void RefreshPlot()
        {
            var info = Chart.GetType().GetMethod("UpdateArea", BindingFlags.NonPublic | BindingFlags.Instance, null,
                new[] {typeof(bool)}, null);

            info?.Invoke(Chart, new object[] { true });

          Console.WriteLine(((ICollection)Chart.Series[0].ItemsSource).Count);

     }


The Count does increase every time I call refresh plot however the chart is not updated. No extra points are added to the screen. Any other suggestions?


Thanks!




DS Durgadevi Selvaraj Syncfusion Team May 4, 2018 11:31 AM UTC

Hi Juliano, 
 
Thanks for your update. 
 
We have analyzed the reported problem. Please call the OnBindingPathChanged method instead of UpdateArea method after changing the collection. Please refer the below code, 
 
Code Snippet[C#] 
 
MethodInfo methodInfo = chart.Series[0].GetType().GetMethod("OnBindingPathChanged", 
                                BindingFlags.NonPublic | BindingFlags.Instance); 
methodInfo?.Invoke(chart.Series[0], new object[] { null }); 


Please let us know if you need any further assistance on this. 
 
Regards, 
Durgadevi.S 



JF Juliano Franz May 8, 2018 05:47 PM UTC

Hi Durgadevi,
It works like a charm! Not sure about performance yet =]
I have ~50 series. To avoid multiple reflection calls I am storing all the MethodInfo in a list. But I still need to iterate over the list to call the method for each series every RefreshInterval.

Anyway, it works =]

Cheers


MK Muneesh Kumar G Syncfusion Team May 9, 2018 04:00 AM UTC

Hi Juliano, 

Thanks for the update.

We are glad to know that the given solution works. Please let us know if you need any further assistance.

Thanks,
Muneesh Kumar G.


DM Diogo Marinho Araujo November 3, 2020 12:45 AM UTC

What is this 'chart' coming from?


SJ Suyamburaja Jayakumar Syncfusion Team November 4, 2020 05:45 PM UTC

Hi Diogo Marinho Araujo, 
 
We were not clear about exact need, please share the expectation in detailed presentation. Which is more helpful us to find your exact requirement and provide a possible solution at earlier. 
 
Regards, 
Suyamburaja J. 


Loader.
Up arrow icon