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

4 posts, 1 answers
  1. Ed
    Ed avatar
    8 posts
    Member since:
    Jul 2013

    Posted 06 Aug 2013 Link to this post

    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,
  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 07 Aug 2013 Link to this post

    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!
  3. Ed
    Ed avatar
    8 posts
    Member since:
    Jul 2013

    Posted 07 Aug 2013 Link to this post

    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
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 09 Aug 2013 Link to this post

    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!
Back to Top