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

AJAX Binding data to Chart with Controller, Action, and additional parameters

3 Answers 144 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 06 Aug 2013, 05:45 AM
I see that it is very easy, and there are several examples, of how to get remote data via AJAX for Charts assuming you don't need to pass any parameters to get the remote data.  How do I pass additional params to the Controller/Action?

FYI, I am using the MVC Extensions.

Thanks in advance,

3 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 07 Aug 2013, 02:22 PM
Hello Ed,

Basically the dataSource is still the same no matter what widget uses its data and you need to use the data function of the read config.

e.g.

@(Html.Kendo().Chart<Kendo.Mvc.Examples.Models.AprilSales>()
    .Name("chart")
    .Legend(false)
    .DataSource(ds => ds.Read(read => read
        .Action("_AprilSales", "Bullet_Charts").Data("nameOfTheJSFunction")
    ))


Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ed
Top achievements
Rank 1
answered on 07 Aug 2013, 11:42 PM
Thanks Petur,
From the docs link your provided, is it also possible to provide a JSON object containing the key/value of the additional data I want to send as opposed to the javascript function that will return the key/value data?
--Ed
0
Petur Subev
Telerik team
answered on 09 Aug 2013, 11:35 AM
Hello Ed,

If I understand you correctly you are trying to return addition data from the server back to the client. 

I am afraid this is not possible using the MVC Wrappers because the response that is expected from the server is as Array that will contain the items.

If instead of array:

[{id:1,foo:"some val"},{id:2,foo:"some other"}]

you return some structure and the array is a nested field
e.g.

{someField:"1",actualData:[{id:1,foo:"some val"},{id:2,foo:"some other"}]}

you cannot specify with the wrapper from which field exactly the collection will be held.

However if you switch and use the JavaScript version of the chart you can do this by specifying the schema.data option.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Charts
Asked by
Ed
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Ed
Top achievements
Rank 1
Share this question
or