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

ItemsSource Problem

Hi, 

I have upgraded from 14.2.026 to the latest 15.x and all my graphs are now missing.  I have changed from DataSource to ItemsSource.  Thank you.



using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Com.Syncfusion.Charts;
using Com.Syncfusion.Charts.Enums;
using Java.Util;
using Java.Text;
using Android.Graphics;
using Android.Webkit;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Sample
{
    [Activity(Label = "Sample", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            var linearLayout = FindViewById(Resource.Id.ChartLinearLayout);

            SfChart chart = new SfChart(this);
            chart.SetBackgroundColor(Color.White);

            chart.PrimaryAxis = new CategoryAxis();
            chart.SecondaryAxis = new NumericalAxis();

            var series = new LineSeriesExt
            {
                //DataSource = GetData1()
                ItemsSource = GetData1() 
            };

            
            chart.Series.Add(series);
            linearLayout.AddView(chart);
        }

        public  ObservableCollection GetData1()
        {
            var datas = new ObservableCollection();
            datas.Add(new ChartDataPoint("2010", 150));
            datas.Add(new ChartDataPoint("2011", 80));
            datas.Add(new ChartDataPoint("2012", 23));
            datas.Add(new ChartDataPoint("2013", 44));
            datas.Add(new ChartDataPoint("2014", 66));
            datas.Add(new ChartDataPoint("2015", 23));
            datas.Add(new ChartDataPoint("2016", 44));
            datas.Add(new ChartDataPoint("2017", 66));
            datas.Add(new ChartDataPoint("2018", 140));
            return datas;
        }
    }

8 Replies

PS Parthiban Sundaram Syncfusion Team September 25, 2017 12:50 PM UTC


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


AK Albert K September 26, 2017 04:45 AM UTC

Hi,

May I ask, why can't I use an ObservableCollection of  ChartDataPoint  as the ItemDataSource?.   

Thank you.



AK Albert K September 26, 2017 06:34 AM UTC

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;

        }

    }

}




PS Parthiban Sundaram Syncfusion Team September 27, 2017 08:12 PM UTC

Hi Albert,

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
 



AK Albert K September 28, 2017 12:56 AM UTC

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.



PS Parthiban Sundaram Syncfusion Team September 28, 2017 05:49 PM UTC

Hi Albert,

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



AK Albert K September 29, 2017 10:41 AM UTC

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



PS Parthiban Sundaram Syncfusion Team October 2, 2017 09:30 AM UTC

Hi Albert,

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

Loader.
Live Chat Icon For mobile
Up arrow icon