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.
Syncfusion Feedback

Refreshing chart on Save

Thread ID:

Created:

Updated:

Platform:

Replies:

132273 Aug 23,2017 09:26 PM Aug 24,2017 06:23 AM Xamarin.Forms 1
loading
Tags: SfChart
Julie Misson
Asked On August 23, 2017 09:26 PM

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

Sivaram Ganesan [Syncfusion]
Replied On August 24, 2017 06:23 AM

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


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.

Warning Icon 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.Close Icon

;