Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,
I was trying to implement kendo line chart with this piece of code.

JavaScript
function createChart() {
            $("#chart").kendoChart({
                dataSource: {
                    transport: {
                        read: {
                            //url: "/Test/test.json",
                            url:"/Employees/GetJsonData",
                            dataType: "json"
                        }
                    },
                    sort: {
                        field: "year",
                        dir: "asc"
                    }
                },
                title: {
                    text: "Employee Track Record"
                },
                legend: {
                    position: "top"
                },
                seriesDefaults: {
                    type: "line"
                },
                series: [{
                    field: "value",
                    name: "Value"
                }],
                categoryAxis: {
                    field: "week",
                    labels: {
                        rotation: -90
                    },
                    crosshair: {
                        visible: true
                    }
                },
                valueAxis: {
                    labels: {
                        format: "N0"
                    },
                    majorUnit: 10000
                },
                tooltip: {
                    visible: true,
                    shared: true,
                    format: "N0"
                }
            });
        }

        $(document).ready(createChart);
        $(document).bind("kendo:skinChange", createChart);





Here, the issue is that my method GetJsonData in Employee Controller is not returning data so that the chart is not being loaded. What I am doing to get data from the controller part is :


C#
public string GetJsonResult([DataSourceRequest]Kendo.Mvc.UI.DataSourceRequest request)
        {
      //some other function here and manipulate to get jsonString like below
           string jsonString = "[{\"week\": \"W1\",\"value\": 3000 },{\"week\": \"W2\",\"value\": 4000},{\"week\": \"W3\",\"value\": 2500}]";
return jsonString;
        }



Since, i need to manipulate json, i just wrote here jsonString which is the string that I would send to jquery datasource. But the datasource wont accept it.



Suppose i write it to json file and read from there then it would be fine where json would be hardcoded on the other way.


So can someone help me out with this one urgently please.


Thanks

What I have tried:

this is what i wrote in json file

[
{
"week": "W1",
"value": 3000
},
{
"week": "W2",
"value": 4000
},
{
"week": "W3",
"value": 2500
}

]
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900