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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dynamic Object, not predefined model in list

Thread ID:

Created:

Updated:

Platform:

Replies:

130010 Apr 14,2017 06:03 AM Jun 25,2017 11:34 PM Xamarin.Forms 9
loading
Tags: SfChart
Devesh
Asked On April 14, 2017 06:03 AM

Hi,

I am trying to add dynamic object to list object, rather than a predefined model. It's working with model, but my data is dynamic which is coming from data base. So i can't keep predefined model. It's something like this. But chart is showing blank.

            SfChart chart = new SfChart();

            CategoryAxis primaryAxis = new CategoryAxis();
            primaryAxis.Title.Text = "Month";
            chart.PrimaryAxis = primaryAxis;

            NumericalAxis secondaryAxis = new NumericalAxis();
            secondaryAxis.Title.Text = "Count";
            chart.SecondaryAxis = secondaryAxis;

            ColumnSeries series = new ColumnSeries();
            List<dynamic> ChartData = new List<dynamic>();

            dynamic seriesmodel1 = new ExpandoObject();
            seriesmodel1.Month = "JAN";
            seriesmodel1.Count = 12;
            ChartData.Add(seriesmodel1);

            dynamic seriesmodel2 = new ExpandoObject();
            seriesmodel2.Month = "FEB";
            seriesmodel2.Count = 92;
            ChartData.Add(seriesmodel2);

            series.ItemsSource = ChartData;
            //series.SetBinding(ChartSeries.ItemsSourceProperty, "ChartData");
            series.XBindingPath = "Month";
            series.YBindingPath = "Count";
            chart.Series.Add(series);

            chart.Title.Text = "Month vs Count";
            this.Content = chart;

Any help would be highly appreciated !

Divya Venkatesan [Syncfusion]
Replied On April 18, 2017 01:33 PM

Hi Devesh,

We have achieved this by overriding GetChartDataPoints() in ChartSeries and return the values as a collection of ChartDataPoints from given ExpandoObjects.

Sample: http://www.syncfusion.com/downloads/support/forum/130010/ze/DynamicObjectSample14960198

Currently this is not supported in iOS platform and you can find more details about this under the following links.

https://forums.xamarin.com/discussion/53941/expandoobject-crashing-ios
https://developer.xamarin.com/guides/ios/advanced_topics/limitations/

Please get back to us if you need further assistance in this.

Regards,
Divya Venkatesan


Devesh
Replied On April 19, 2017 12:03 AM

Hi Divya,

This is a big surprise for me. If it doesn't work in IOS & Android both, then it doesn't make any sense to use this approach. For a moment, if i accept this approach then tell me that do i need to create custom series class for each series type to support dynamic object ? Also let me know, using dynamic object rather than using a predefined model is a limitation of Syncfusion or Xamarin ?

In a practical scenario, specially when you are dealing with dynamic data it's absolutely not possible to use a predefined model object and that's why we choose dynamic object. If it's a limitation of Syncfusion, then it;s gonna be a big issue for me to manage things.

Please clarify the same soon.





Divya Venkatesan [Syncfusion]
Replied On April 20, 2017 12:11 PM

Hi Devesh,

Thanks for the update.

Regarding "using dynamic object rather than using a predefined model is a limitation of Syncfusion or Xamarin ?"

Currently this is a limitation in Xamarin iOS platform since Mono on the iPhone does not support any form of dynamic code generation.

You can read more about this limitation in Xamarin under the following links.

https://developer.xamarin.com/guides/ios/advanced_topics/limitations/

https://forums.xamarin.com/discussion/53941/expandoobject-crashing-ios

Please let us know if you have any queries.

Regards,
Divya Venkatesan

Devesh
Replied On April 20, 2017 11:39 PM

Hi Divya,

Thanks for your reply.

According to you, i won't be able to use Syncfusion charts with dynamic objects in iOS, since Mono on the iPhone does not support any form of dynamic code generation. I have to use predefined model only.

Please correct me if i am wrong.

Also, i have asked two queries. You have replied to only one. I think you have missed one. It would be really nice, if you can reply to another query also.
Please read my previous reply.

Saravana Pandian Murugan [Syncfusion]
Replied On April 24, 2017 03:25 PM

Hi Devesh,

Regarding "i won't be able to use dynamic objects in iOS, since Mono on the iPhone does not support"

Yes. This is not possible due to the mentioned limitations in iOS platform in framework itself.

Regarding "do i need to create custom series class for each series type to support dynamic object "

Yes. Currently this is the best possible approach to use ExpandoObject as a model for the data points for SfChart. Please get back to us if you have any issues or need assistance on this.

Regards,
Saravana Pandian M.


Devesh
Replied On April 25, 2017 01:03 AM

Hi Devesh,

Regarding "i won't be able to use dynamic objects in iOS, since Mono on the iPhone does not support"

Yes. This is not possible due to the mentioned limitations in iOS platform in framework itself.

Regarding "do i need to create custom series class for each series type to support dynamic object "

Yes. Currently this is the best possible approach to use ExpandoObject as a model for the data points for SfChart. Please get back to us if you have any issues or need assistance on this.

Regards,
Saravana Pandian M.


Thanks a lot for your straight forward answer.

Saravana Pandian Murugan [Syncfusion]
Replied On April 26, 2017 03:09 AM

Hi Devesh,

Thanks for the update. Please let us know if you need any further assistance.

Regards,
Saravana Pandian M.


Andrey Lurye
Replied On June 23, 2017 05:16 PM

This solution of using a dictionary instead of an expandoobject worked for me under Xamarin forms for android and ios

https://www.beejblog.com/2017/06/syncfusion-xamarin-forms-sfdatagrid-binding-to-listdictionary.html

the 2 tricks are

create the columns manually mapping as

 MappingName = "Vals[Source]"

then wrap your dictionary in an object 

  public class DictRow

  {

    public Dictionary<string, object> Vals { get; set; }

    public DictRow(Dictionary<string, object> dict) { Vals = dict; }

  }

I hope this helps someone


Devesh
Replied On June 25, 2017 11:34 PM

This solution of using a dictionary instead of an expandoobject worked for me under Xamarin forms for android and ios

https://www.beejblog.com/2017/06/syncfusion-xamarin-forms-sfdatagrid-binding-to-listdictionary.html

the 2 tricks are

create the columns manually mapping as

 MappingName = "Vals[Source]"

then wrap your dictionary in an object 

  public class DictRow

  {

    public Dictionary<string, object> Vals { get; set; }

    public DictRow(Dictionary<string, object> dict) { Vals = dict; }

  }

I hope this helps someone


Thanks Andrey for you solution. There could be other alternatives also. I have used another one without creating a dictionary object but it's similar to this one.

But using alternatives, we won't be able to get dynamic behavior.

Anyways, thanks again :)


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.

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

;