我是kendo UI的新手,我的问题是:我正在使用Asp.net MVC,而我正在尝试使用传输Url绑定基诺图表,但它是'我没有工作,我已经过了一整天寻找解决方案,但找不到一个,谢谢你的帮助:这是我的代码:
<script> $("#chart").kendoChart({
dataSource: {
transport: {
read: {
url: "@Html.Raw(Url.Action("Showchart", "Chart"))",
dataType: "json"
}
},
sort: {
field: "year",
dir: "asc"
}
}
});
</script>
Controller:
public ActionResult Showchart()
{
List<RootObject> Mylist = new List<RootObject>();
RootObject object1 = new RootObject();
object1.sales = 200;
object1.year ="1990";
Mylist.Add(object1);
RootObject object2 = new RootObject();
object2.sales = 230;
object2.year = "2008";
Mylist.Add(object2);
RootObject object3 = new RootObject();
object3.sales = 260;
object3.year = "2007";
Mylist.Add(object3);
RootObject object4 = new RootObject();
object4.sales = 659;
object4.year = "2006";
Mylist.Add(object4);
RootObject object5 = new RootObject();
object5.sales = 400;
object5.year = "2000";
Mylist.Add(object5);
return Json(Mylist);
}
}
public class RootObject
{
public int sales;
public string year;
}
答案 0 :(得分:0)
请尝试使用以下代码段。
查看强>
<div id="chart"></div>
<script>
$("#chart").kendoChart({
dataSource: {
transport: {
read: {
url: "@Html.Raw(Url.Action("Showchart", "YourControllerName"))",
dataType: "json"
}
},
sort: {
field: "year",
dir: "asc"
}
},
seriesDefaults: {
type: "area"
},
series: [{
field: "sales",
name: "sales"
}],
categoryAxis: {
field: "year"
},
});
</script>
<强> CONTROLLER 强>
public ActionResult Showchart()
{
List<RootObject> Mylist = new List<RootObject>();
RootObject object1 = new RootObject();
object1.sales = 200;
object1.year = "1990";
Mylist.Add(object1);
RootObject object2 = new RootObject();
object2.sales = 230;
object2.year = "2008";
Mylist.Add(object2);
RootObject object3 = new RootObject();
object3.sales = 260;
object3.year = "2007";
Mylist.Add(object3);
RootObject object4 = new RootObject();
object4.sales = 659;
object4.year = "2006";
Mylist.Add(object4);
RootObject object5 = new RootObject();
object5.sales = 400;
object5.year = "2000";
Mylist.Add(object5);
return Json(Mylist, JsonRequestBehavior.AllowGet);
}
注意:1)要运行上面的代码,您必须在视图代码中添加所需的kendo javascript库。 2)将“YourControllerName”文本替换为视图中的控制器名称。
如果有任何疑虑,请告诉我。