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
close icon

Json data binding

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)
        {
        }
    }
}

1 Reply

YP Yuvaraj Palanisamy Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon