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;
}
}
}
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.
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);