We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Chart not update when modify collection

I have used code behind technique to bind chart with collection by using ItemSource Property but the problem is if i modify collection i have to rebind the chart it does not refresh automatically.

7 Replies

GM Gobi M Syncfusion Team May 25, 2016 01:15 PM UTC

Hi Atif, 
 
Thanks for contacting Syncfusion support. 
 
We are able to achieve your requirement using ListerPropertyChange property. We have prepared a sample which can be downloaded from the below location. 
 
 
Please let us know for any concerns. 
 
Regards, 
Gobi M 



AT Atif May 25, 2016 06:36 PM UTC

Thanks a lot!

Well I am binding chart at code behind .
I have four Collections Hour , Weekly , Monthly , Yearly and inside view I have one chart control and four buttons on each button click I change the ItemSource property of the chart.

I call this method on each click and my view bind the chart with four different collections.
      public   void OnFilterGraphByType()
        {
            switch (FilterType)
            {
                case "Daily":
                    this.BindingContext = MyWellness.VMViewModelStatic.Temperature_HourData;
                    break;
                case "Weekly":
                    this.BindingContext = MyWellness.VMViewModelStatic.Temperature_WeekData;
                    break;
                case "Monthly":
                    this.BindingContext = MyWellness.VMViewModelStatic.Temperature_MonthData;
                    break;
                case "Yearly":
                    this.BindingContext = MyWellness.VMViewModelStatic.Temperature_YearData;
                    break;
            }
        }

If I use your technique it works perfect but I have different data on each filter that's why I have four collections
Right now on Add and update methods I am using Messaging of xamarin forms to achieve the result but I would love to have automatic mechanism because I have 10 different charts in my app.

Thanks.


GM Gobi M Syncfusion Team May 26, 2016 10:14 AM UTC

Hi Atif, 
 
We are able achieve your requirement for dynamic chart series collection change. We have prepared a sample for this and it can be downloaded in the below link. 
 
 
Please let us know if you need any further assistance.  
 
Regards, 
Gobi M 



AT Atif May 26, 2016 03:54 PM UTC

Well I have already used this technique my problem is if I modify collection means to say if add new entries in hour , daily, monthly collection so after modification I have to click on the filter button to get the latest changes I am looking for auto update...


GM Gobi M Syncfusion Team May 27, 2016 10:58 AM UTC

Hi Atif, 
  
We would like to clarify the exact requirement with you, for providing better solution asap.  
  
You have a chart with one series and it initially bound with any one of the (hourly, monthly or daily) data collection. Your requirement is to replace the Chart ItemsSource with the data, which is modified (ex. Add, remove, insert...) dynamically, without any action. 
  
For an example: Initially chart rendered with Year data. Now adding one data to month collection and it should automatically update chart series with month data without clicking on any filters." 
  
If this is not your requirement, kindly update us the requirement in details to assist you better. 
  
Regards, 
Gobi M 



UN Unknown Syncfusion Team October 17, 2018 11:19 PM UTC

How might we do that with annotations? Since they dont have ListerPropertyChange


MP Michael Prabhu M Syncfusion Team October 18, 2018 10:33 AM UTC

Hi Mark, 

Greetings from Syncfusion, for ChartAnnotations, there is no need for ListenPropertyChange. We can directly change all the properties of ChartAnnotations dynamically. Based on that we have prepared a simple sample to dynamically change the properties of RectangleAnnotation on a timer and it can be downloaded from the below link. 

Sample: 124212  

Code snippet [XAML] 
<chart:SfChart.ChartAnnotations> 
       <chart:RectangleAnnotation x:Name="rectangleAnno" X1="1" Y1="15" X2="2" Y2="20" Text="Rect" /> 
</chart:SfChart.ChartAnnotations> 
 

Code snippet [C#] 
public MainPage() 
{ 
   InitializeComponent(); 
   UpdateAnnotation(); 
} 
 
async void UpdateAnnotation() 
{ 
  await Task.Delay(1000); 
 
   rectangleAnno.Y1 = y1 + 5; 
  rectangleAnno.Y2 = y2 + 5; 
 
  y1 = y1 + 5; 
  y2 = y2 + 5; 
 
  if(y2 < 70) 
     UpdateAnnotation(); 
} 
 

Hope this helps. 

Thanks, 
Michael 


Loader.
Up arrow icon