- Home
- Forum
- Xamarin.Forms
- Json data binding, Problem trying to plot according to the field
Json data binding, Problem trying to plot according to the field
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)
{
}
}
}
SIGN IN To post a reply.
1 Reply
MP
Michael Prabhu M
Syncfusion Team
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
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
BD Brayan Daniel Caldera
- Nov 21, 2018 05:17 AM UTC
- Nov 22, 2018 10:49 AM UTC