This is a migrated thread and some comments may be shown as answers.

ASP.NET MVC Razor: StockChart. Bind to dynamic number of series.

2 Answers 135 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 2
Aaron asked on 01 Nov 2013, 04:35 AM
I am currently implementing a StockChart in razor.

I was able to get the chart binding nicely to a single series, but I am having trouble working out how to bind the chart to a dynamic number of series.

For example,  consider a series which is a list of objects (foo) having a date and decimal property. 

If I have x number of series, so something like List<List<foo>>data. How do I bind this to the chart?

2 Answers, 1 is accepted

Sort by
0
Accepted
T. Tsonev
Telerik team
answered on 05 Nov 2013, 08:47 AM
Hi,

You can loop through the model and add the series, binding them directly to the List<foo> collections:
    .DateField("date")
    .Series(series => {
        for (List<List<Foo>> data in ViewBag.Series) {
            series.Column(data);
        }
    })


The series fields can't be set this way (we'll fix this) and you need to use the default field names: value and the one specified by DateField:

public class Foo {
    public decimal value { ... }
    public DateTime date { ... }
}


I hope this helps.
Regards,
T. Tsonev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Aaron
Top achievements
Rank 2
answered on 05 Nov 2013, 10:30 PM
Thanks!
I must have been so close to working it out by accident! I had hooked up DateField correctly but didn't follow the convention of calling the data field 'value'.

I've just changed my code to follow your method. It is much simpler than what I had implemented. I was using ExpandoObject to dynamically add properties to an object (one property per series). That allowed me to tell the chart which member to use for each series. Very messy but it worked.

Thanks for your help!

Cheers
Aaron
Tags
Charts
Asked by
Aaron
Top achievements
Rank 2
Answers by
T. Tsonev
Telerik team
Aaron
Top achievements
Rank 2
Share this question
or