I have a Kendo Chart defined on my cshtml page as below:
@(Html.Kendo().Chart<MyModel>()
.Name("chart")
.Title("")
.Legend(legend => legend
.Visible(false)
)
.Series(series =>
{
series.Scatter(model => model.X, model => model.Y);
series.Scatter(model => model.X, model => model.Y);
})
)
I need to set the data of each of these series using a JQuery call.
My JQuery call and returning data works fine, and the below will populate the first series data:
function GetChartData(ex,ten) {
var str = "{'arg': '" + ex + "', 'arg2': '" + ten ' }";
$.ajax({
type: 'POST',
url: '/Controller/CreateChartData',
dataType: "json",
contentType: "application/json; charset=utf-8",
data: str ,
success: function (data) {
var grid = $("#chart").data("kendoChart");
grid.dataSource.data(data.ChartData);
grid.refresh();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
I am however, unable to set the second series data.
I have tried the following which rendered nothing on the chart:
function GetChartData(ex,ten) {
var str = "{'arg': '" + ex + "', 'arg2': '" + ten ' }";
$.ajax({
type: 'POST',
url: '/Controller/CreateChartData',
dataType: "json",
contentType: "application/json; charset=utf-8",
data: str ,
success: function (data) {
var grid = $("#chart").data("kendoChart");
grid.options.series[0].data = data.ChartData;
grid.options.series[1].data = data.ChartDataSeries2;
grid.refresh();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
Something you might try, is to not initialize that chart until after you have all the data.
That way instead of calling refresh() you can pass both series to the .kendoChart() method
Working aspx example page: