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

Dynamic Object, not predefined model in list

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 !

9 Replies

DV Divya Venkatesan Syncfusion Team April 18, 2017 05:33 PM UTC

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



DE Devesh April 19, 2017 04:03 AM UTC

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.






DV Divya Venkatesan Syncfusion Team April 20, 2017 04:11 PM UTC

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


DE Devesh April 21, 2017 03:39 AM UTC

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.


SP Saravana Pandian Murugan Syncfusion Team April 24, 2017 07:25 PM UTC

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.



DE Devesh replied to Saravana Pandian Murugan April 25, 2017 05:03 AM UTC

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.


SP Saravana Pandian Murugan Syncfusion Team April 26, 2017 07:09 AM UTC

Hi Devesh,

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

Regards,
Saravana Pandian M.



AL Andrey Lurye June 23, 2017 09:16 PM UTC

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



DE Devesh replied to Andrey Lurye June 26, 2017 03:34 AM UTC

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


Loader.
Up arrow icon