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

Json data binding

Thread ID:

Created:

Updated:

Platform:

Replies:

132944 Sep 29,2017 01:09 PM UTC Oct 2,2017 01:41 PM UTC Xamarin.Forms 1
loading
Tags: SfChart
Carlo Chan
Asked On September 29, 2017 01:09 PM UTC

hey. Having trouble binding json data to a sf chart with having date on the x axis and field1 on the y axis could you please help out with this thanks

Here is my json deserialization
public class RootObject
    {

        public List<Feed> Feeds { getset; }
    }

    public class Channel
    {
        public int Id { getset; }
        public string Name { getset; }
        public string Description { getset; }
        public string Latitude { getset; }
        public string Longitude { getset; }
        public string Field1 { getset; }
        public DateTime Created_at { getset; }
        public DateTime Updated_at { getset; }
        public string Elevation { getset; }
        public int Last_entry_id { getset; }
    }

    public class Feed
    {
        public DateTime Created_at { getset; }
        public int Entry_id { getset; }
        public string Field1 { getset; }
    }


    public partial class DripPage : TabbedPage
    {
        void Handle_Refreshing(object sender, System.EventArgs e)
        {
            postsListView.ItemsSource = _data;
            postsListView.EndRefresh();
        }

        private const string Url = "https://thingspeak.com/channels/301726/field/1.json";
        private HttpClient _client = new HttpClient();
        private ObservableCollection<Feed> _data;

    
        public DripPage()
        {
            InitializeComponent();
        }

        protected override async void OnAppearing()
        {
            var content = await _client.GetStringAsync(Url);
            var data = JsonConvert.DeserializeObject<RootObject>(content);

            _data = new ObservableCollection<Feed>(data.Feeds);
            postsListView.ItemsSource = _data;

    
            base.OnAppearing();
        }

        void OnAdd(object sender, System.EventArgs e)
        {
        }

        void OnUpdate(object sender, System.EventArgs e)
        {
        }

        void OnDelete(object sender, System.EventArgs e)
        {
        }
    }
}

Yuvaraj Palanisamy [Syncfusion]
Replied On October 2, 2017 01:41 PM UTC

Hi Carlo chan,

Thank for contacting Syncfusion support.

We have analyzed your code snippet, and you are missing to set the collection values for binding context instance and also not inherited by INotifyPropertyChanged interface of RootObject Class. We have modified the sample as per your requirement. Please find the attached sample from the below link.

Sample : http://www.syncfusion.com/downloads/support/forum/132944/ze/ChartGettingStarted1623762518  

Regards,
Yuvaraj 


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

;