- Home
- Forum
- Xamarin.Android
- ItemsSource Problem
ItemsSource Problem
Hi Albert,
Thanks for contacting Syncfusion support.
Now you can assign a collection of custom objects to the ItemsSource property. In this case, you need to set the XBindingPath and YBindingPath properties of chart series with the property names of the custom object which contains the x-value/category and y-value respectively. Please find the sample from the below location.
Sample: http://www.syncfusion.com/downloads/support/forum/132809/ze/Sample731643377
Documentation: https://help.syncfusion.com/xamarin-android/sfchart/populating-data
Please let us know if you have any queries.
Regards,
Parthiban
Hi,
May I ask, why can't I use an ObservableCollection of ChartDataPoint as the ItemDataSource?.
Thank you.
Hi,
I have another problem with DateTime on the Y - axis. I am getting error at the line series.YBindingPath = "YValue". The error message is System.InvalidCastException: Specified cast is not valid.
Is this a bug?
Thank you.
Regards,
using Android.App;
using Android.Widget;
using Android.OS;
using System.Collections.ObjectModel;
using Com.Syncfusion.Charts;
using Android.Graphics;
using Android.Views;
using Java.Util;
using System.Collections.Generic;
using System;
namespace ItemsSouceSample
{
[Activity(Label = "ItemsSouceSample", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
SfChart chart;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
chart = new SfChart(this);
chart.SetBackgroundColor(Color.White);
//chart.PrimaryAxis = new CategoryAxis();
chart.PrimaryAxis = new DateTimeAxis();
chart.SecondaryAxis = new NumericalAxis();
SplineSeries series = new SplineSeries();
series.ItemsSource = GetData();
series.XBindingPath = "XValue";
series.YBindingPath = "YValue";
chart.Series.Add(series);
SetContentView (chart);
}
public static ObservableCollection<DataModel> GetData()
{
var datas = new ObservableCollection<DataModel>();
Calendar cal = new GregorianCalendar();
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds();
datas.Add(new DataModel(cal, 150));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds()+ 30000;
datas.Add(new DataModel(cal, 80));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 30000;
datas.Add(new DataModel(cal, 23));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 30000;
datas.Add(new DataModel(cal, 44));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 30000;
datas.Add(new DataModel(cal, 66));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 30000;
datas.Add(new DataModel(cal, 23));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 30000;
datas.Add(new DataModel(cal, 44));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 30000;
datas.Add(new DataModel(cal, 66));
cal.TimeInMillis = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 30000;
datas.Add(new DataModel(cal, 140));
return datas;
}
}
public class DataModel
{
//public string XValue { get; set; }
public Calendar XValue { get; set; }
public double YValue { get; set; }
public DataModel(Calendar xVal, double yVal)
{
XValue = xVal;
YValue = yVal;
}
}
}
Thanks for the update.
We should provide C# data type values to ItemsSource property and it won’t work for the values which are derived from java.lang.Object. So, we request you to use DateTime instead of Calendar to overcome this issue. We have prepared the sample based on code snippet provided by you, please download the sample from following location.
Sample: http://www.syncfusion.com/downloads/support/forum/132809/ze/ItemsSouceSample1525029848
Please let us know, if you need further assistance on this.
Regards,
Parthiban S
Hi,
I would like to know how to use the DateTimeAxis as the PrimaryAxis. Your example is setting it to CatergoryAxis.
Also, Is ChartDataPoint going to be deprecated?, If not, Is it still possible to use in conjunction with ItemsSource in particular when PrimaryAxis is a DateTimeAxis.
Prior to version 15.3 everything worked perfectly. Thank you.
Sorry for the inconvenience caused.
Please ignore the previous attached sample. We have modified the sample with DateTimeAxis as Primary Axis. Please download the sample from following location.
Sample: http://www.syncfusion.com/downloads/support/forum/132809/ze/ItemsSouceSample-1533183546
Please let us know, if you need further assistance on this.
Regards,
Parthiban S
Hi,
I have a further issue with DataMarker which used to work before. The line of codes marked in Red below, does not seems to have any effect on the spline chart. The marker shows but it is in its default setting. Please take a look. Thank you.
chart = new SfChart(this);
chart.SetBackgroundColor(Color.White);
//chart.PrimaryAxis = new CategoryAxis();
chart.PrimaryAxis = new DateTimeAxis();
chart.SecondaryAxis = new NumericalAxis();
SplineSeries series = new SplineSeries() {SplineType= SplineType.Monotonic };
series.ItemsSource = GetData();
series.XBindingPath = "XValue";
series.YBindingPath = "YValue";
series.DataMarker.LabelStyle.TextColor = Color.Black;
series.DataMarker.LabelStyle.OffsetY = 10;
series.DataMarker.LabelStyle.OffsetX = 10;
series.DataMarker.MarkerType = DataMarkerType.Hexagon;
series.DataMarker.ShowLabel = true;
chart.Series.Add(series);
SetContentView (chart);
Thanks for the update.
We have created an incident under your Direct Trac account. So, we request to follow the incident for further details.
Our Direct Trac support system can be accessed from the following link:
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents
Regards,
Parthiban S
- 8 Replies
- 2 Participants
-
AK Albert K
- Sep 22, 2017 08:24 AM UTC
- Oct 2, 2017 09:30 AM UTC