简体   繁体   中英

How to change the model of an ASP .Net MVC Kendo Chart using javascript?

I am using the kendo UI MVC wrapper to create a chart. The chart is using a model:

@(Html.Kendo().Chart<ModelA>()
....

I wish to change the model used by the chart and reload using a new datasource. I am changing the datasource in javascript like this:

....
var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/Controller/_ChartData",
            type: "POST",
            data: dataID
            }
     }
 });

This is firing on a button click to reload the data. The data is reloading correctly. Is this the correct way to change the datasource and how do i change the model that the chart is using (ModelA -> ModelB)

Just modify the dataSource...

var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
                url: "/Controller/_ChartData",
                type: "POST",
                data: dataID
            }
        }
    }, 
    schema: {
        model: {
            // ModelB details go here
        }
    });

Have a look at the Kendo documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM