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
close icon

What am I doing wrong with observable collection?

XAML snippet for Form

    <chart:SfChart x:Name="Chart" HeightRequest="300" WidthRequest="200" >

      <chart:SfChart.PrimaryAxis>
        <chart:DateTimeAxis IntervalType="Days" >
          <chart:DateTimeAxis.LabelStyle>
            <chart:ChartAxisLabelStyle LabelFormat = "MM-dd-yy"></chart:ChartAxisLabelStyle>
          </chart:DateTimeAxis.LabelStyle>
        </chart:DateTimeAxis>
      </chart:SfChart.PrimaryAxis>

      <chart:SfChart.SecondaryAxis>
        <chart:NumericalAxis Maximum="0" Minimum="5" Interval="0.5">
        </chart:NumericalAxis>
      </chart:SfChart.SecondaryAxis>

      <chart:SfChart.Series>
        <chart:LineSeries ItemsSource ="{Binding Data}" XBindingPath="DateTimeStamp" YBindingPath="Score" Color="Red" />
      </chart:SfChart.Series>

    </chart:SfChart>
  

Code in ViewModel:
        public ObservableCollection<StandardsFeedback> Data 
        {
            get;
            set;
        }
When I add or delete from this collection the chart does not update. Even if I trigger the OnPropertyChanged

3 Replies

DV Divya Venkatesan Syncfusion Team April 10, 2017 02:39 PM UTC

Hi David,

We have done the sample to showcase adding or removing data from ObservableCollection. Please download the sample from following location.

Sample: http://www.syncfusion.com/downloads/support/forum/129905/ze/LineChart1741757198

Please get back to us if you are still facing issues in this.

Regards,
Divya Venkatesan



DW David White April 10, 2017 06:41 PM UTC

Your sample app works fine. There is only one problem, it does not work with a ViewModel. In the MVVM framework I am using, updates to data are done in the ViewModel and then you notify through the  INotifyPropertyChanged interface. Instead of hooking to a Clicked event I put a Command in that resides in the ViewModel and then update data from there.
In the ViewModel
        public Command FirstTimeCommand { getset; }
        private void FirstTime(object obj)
        {
                Data.Add(new StandardsFeedback(new DateTime(20160107), 4));
        }
in the form
        <Button x:Name="button1" Text="Add" Command="{Binding FirstTime}"/>


DV Divya Venkatesan Syncfusion Team April 11, 2017 04:52 PM UTC

Hi David,

We suspect that you are binding to FirstTime() instead of FirstTimeCommand property. We have also modified the sample and attached for your reference.

Sample: http://www.syncfusion.com/downloads/support/forum/129905/ze/LineChart754213584

Please get back to us if you need further assistance on this.

Regards,
Divya Venkatesan


Loader.
Live Chat Icon For mobile
Up arrow icon