Setting Multiple chart series datasource through JQuery

1 posts, 0 answers
  1. Ben
    Ben avatar
    1 posts
    Member since:
    Sep 2012

    Posted 19 Sep 2012 Link to this post

    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. 


     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);
                    }
                });

    The above will set the 1st series data, but I need to be able to set the second series as well. I have all of the data returning correctly from the database, but no way of setting both 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);
                    }
                });

     
                      
Back to Top