Articles in this section
Category / Section

How to update an existing data point in Xamarin.Forms Chart?

1 min read

To update the existing data points dynamically, set the ListenPropertyChange property of ChartSeries to true to let the SfChart to listen the Model property changes. The default value of this property is false.

XAML:

<chart:SfChart.Series>
       <chart:ColumnSeries x:Name="series" ItemsSource="{Binding Data}" 
                           XBindingPath="Value" YBindingPath="Size" 
                           ListenPropertyChange="True">
       </chart:ColumnSeries>
</chart:SfChart.Series>

 

Also, Model class should be implemented the INotifyPropertyChanged. The following code example illustrates model class for a reference.

C#:

public class ChartDataModel : INotifyPropertyChanged
{
    public ChartDataModel(double value, double size)
    {
        Value = value;
        Size = size;
    }
 
    private double value;
 
    public double Value
    {
        get { return value; }
        set
        {
            this.value = value;
            RaisePropertyChanged("Value");
        }
     }
 
     private double size;
 
     public double Size
     {
         get { return size; }
         set
         {
              size = value;
              RaisePropertyChanged("Size");
         }
      }
 
      public event PropertyChangedEventHandler PropertyChanged;
 
      void RaisePropertyChanged(string name)
      {
           if (PropertyChanged != null)
               PropertyChanged(this, new PropertyChangedEventArgs(name));
      }
}

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied