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

Refreshing chart on Save

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 { getset; }
       
        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

1 Reply

SG Sivaram Ganesan Syncfusion Team August 24, 2017 10:23 AM UTC

Hi Julie,

Thanks for contacting Syncfusion support.

Chart will be automatically refreshed if we add, remove, insert and clear the data from ItemsSource at any time if the data is type of ObservableCollection.

We have prepared a sample based on this and it can be downloaded from below location.

Sample link: http://www.syncfusion.com/downloads/support/forum/132273/ze/ItemsSourceSample1256786745

Please get back to us on further assistance on this.

Regards,
Sivaram.G


Loader.
Live Chat Icon For mobile
Up arrow icon