Hi Guys,
I was trying to implement kendo line chart with this piece of code.
function createChart() {
$("#chart").kendoChart({
dataSource: {
transport: {
read: {
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 :
public string GetJsonResult([DataSourceRequest]Kendo.Mvc.UI.DataSourceRequest request)
{
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
}
]