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.
Unfortunately, activation email could not send to your email. Please try again.

What am I doing wrong with observable collection?

Thread ID:

Created:

Updated:

Platform:

Replies:

129905 Apr 8,2017 09:59 PM Apr 11,2017 12:52 PM Xamarin.Forms 3
loading
Tags: SfChart
David White
Asked On April 8, 2017 09:59 PM

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

Divya Venkatesan [Syncfusion]
Replied On April 10, 2017 10:39 AM

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


David White
Replied On April 10, 2017 02:41 PM

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}"/>

Divya Venkatesan [Syncfusion]
Replied On April 11, 2017 12:52 PM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;