- Home
- Forum
- Xamarin.Forms
- What am I doing wrong with observable collection?
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>
<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;
}
{
get;
set;
}
When I add or delete from this collection the chart does not update. Even if I trigger the OnPropertyChanged
SIGN IN To post a reply.
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
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 { get; set; }
private void FirstTime(object obj)
{
Data.Add(new StandardsFeedback(new DateTime(2016, 01, 07), 4));
}
{
Data.Add(new StandardsFeedback(new DateTime(2016, 01, 07), 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
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
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
DW David White
- Apr 9, 2017 01:59 AM UTC
- Apr 11, 2017 04:52 PM UTC