I have an sfChart for Xamarin forms.
How do I add a new value, click a save button and have the chart refreshed.
This is my ViewModel
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using BeatPain.Database;
using System.Linq;
namespace BeatPain
{
public class PainScoreViewModel
{
public RewardDatabase database;
public ObservableCollection<PainScoreDB> Items { get; set; }
public PainScoreViewModel()
{
database = new RewardDatabase();
Items = new ObservableCollection<PainScoreDB>();
Items.Clear();
var items = (from i in database.GetItems<PainScoreDB>()
orderby i.PainDateSetDB
select i);
foreach (var item in items)
Items.Add(item);
}
}
}
My chart XAML
<chart:SfChart Grid.Row="6" x:Name="painChart">
<chart:SfChart.PrimaryAxis>
<chart:CategoryAxis>
<chart:CategoryAxis></chart:CategoryAxis>
</chart:CategoryAxis>
</chart:SfChart.PrimaryAxis>
<chart:SfChart.SecondaryAxis>
<chart:NumericalAxis Minimum="0" Maximum="10" Interval="1">
<chart:NumericalAxis.Title>
<chart:ChartAxisTitle Text="Pain Score"></chart:ChartAxisTitle>
</chart:NumericalAxis.Title>
</chart:NumericalAxis>
</chart:SfChart.SecondaryAxis>
<chart:SfChart.Series>
<chart:ColumnSeries ItemsSource="{Binding Items}" XBindingPath="PainDateSetDB" YBindingPath="ScoreDB" Color="{StaticResource PositiveBackgroundColorUnselected}"
ListenPropertyChange="True">
<chart:ColumnSeries.ColorModel>
<chart:ChartColorModel Palette="None"/>
</chart:ColumnSeries.ColorModel>
<chart:ColumnSeries.DataMarker>
<chart:ChartDataMarker ShowLabel="True"/>
</chart:ColumnSeries.DataMarker>
</chart:ColumnSeries>
</chart:SfChart.Series>
</chart:SfChart>
I have attached a screen shot. What I wish to do, is change the range, click on the save button, and for the chart on the same page to be refreshed.
Thankyou
Attachment:
Screen_Shot_20170824_at_11.23.28_am_72799400.zip