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

Setting Multiple chart series datasource through JQuery

0 Answers 87 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 19 Sep 2012, 01:41 PM
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);
                }
            });

 
                  

No answers yet. Maybe you can help?

Tags
Charts
Asked by
Ben
Top achievements
Rank 1
Share this question
or