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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Json data binding, Problem trying to plot according to the field

Thread ID:

Created:

Updated:

Platform:

Replies:

141061 Nov 21,2018 05:17 AM UTC Nov 22,2018 10:49 AM UTC Xamarin.Forms 1
loading
Tags: SfChart
Brayan Daniel Caldera
Asked On November 21, 2018 05:26 AM UTC

I have a problem trying to plot regardless the field, here is my json deserialization.

namespace SyncFusion2
{
    public  class RootObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        ObservableCollection feeds = new ObservableCollection();
        public ObservableCollection Feeds
        {
            get { return feeds; }
            set
            {
                feeds = value;
                NotifyPropertyChanged();
            }
        }

        protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class Feed
    {
        public DateTime Created_at { get; set; }
        public int Entry_id { get; set; }
        public string Field1 { get; set; }
        public string Field2 { get; set; }
        public string Field3 { get; set; }
        public string Field4 { get; set; }
        public string Field5 { get; set; }
        public string Field6 { get; set; }
        public string Field7 { get; set; }
        public string Field8 { get; set; }
    }

    public partial class MainPage : ContentPage
    {
        private const string Url = "https://thingspeak.com/channels/613888/feed.json";
        
        private HttpClient _client = new HttpClient();
        public ObservableCollection _data;

        public MainPage()
        {
            InitializeComponent();
        }

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

            rootObject.Feeds = new ObservableCollection(data.Feeds);
            //series.ItemsSource = _data;
            //series.XBindingPath = "Created_at";
            //series.YBindingPath = "Entry_id";

            base.OnAppearing();
        }

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

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

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

    }

and my drip page

namespace SyncFusion2
{
    class DripPage : ContentPage
    {
        private const string Url = "https://thingspeak.com/channels/613888/feed.json";
        private HttpClient _client = new HttpClient();
        private ObservableCollection _data;
        SfChart chart;
        LineSeries series;

        public DripPage()
        {
            chart = new SfChart();
            series = new LineSeries();
            Content = chart;
        }

        protected override async void OnAppearing()
        {
            var content = await _client.GetStringAsync(Url);
            var data = JsonConvert.DeserializeObject(content);
            _data = new ObservableCollection(data.Feeds);

            series.ItemsSource = _data;
            series.XBindingPath = "Created_at";
            series.YBindingPath = "Field1";
            chart.Series.Add(series);

            base.OnAppearing();
        }

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

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

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

Michael Prabhu M [Syncfusion]
Replied On November 22, 2018 10:49 AM UTC

Hi Brayan, 
 
Greetings from Syncfusion. 
 
We have prepared a sample based on your code snippet and we like to let you know that numerical axis accepts only double, float and integer type values. In your code snippet you bound string value to YBindingPath. So please give correct format for ItemSource values. Please refer the below screenshot. 
 
Screenshot: 
 
 
We have attached the prepared sample for your reference. 
 
Sample: 141061_json 
 
Thanks, 
Michael  
 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon