2
我有方法,我的控制器上,誰返回JSON爲什麼Google Chart不起作用ASP MVC應用程序?
[HttpPost]
public JsonResult CompanyChart()
{
var data = db.adusers;
var selectUsers = from s in data where (s.Company != null) select s;
int fenixPlus = (from fP in data where (fP.Company == "ООО \"Феникс+\"") select fP).Count();
int fenixPresent = (from fP in data where (fP.Company == "ООО \"Феникс-Презент\"") select fP).Count();
var dataObj = new object[]
{
new object[] {"Компания","Количество"},
new object[] { "ООО \"Феникс+\"", fenixPlus},
new object[] { "ООО \"Феникс-Презент\"", fenixPresent}
};
return Json(dataObj, JsonRequestBehavior.AllowGet);
}
的Json看起來像這樣 [["Компания","Количество"],["ООО \"Феникс+\"",53],["ООО \"Феникс-Презент\"",42]]
在我看來身邊,我有一個jquery post請求
$.ajax({
url: '@Url.Action("CompanyChart", "Users")',
type: 'post',
dataType: "json",
success: function (data) {
drawChart(data);
}
});
然後,我嘗試畫谷歌餅圖
google.charts.load("current", { packages: ["corechart"] });
google.charts.setOnLoadCallback(drawChart);
function drawChart(data) {
var array = JSON.parse(data);
var dataV = new google.visualization.DataTable(array);
var options = {
title: 'My Daily Activities',
pieHole: 0.4,
};
var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
chart.draw(dataV, options);
};
不能正常工作,控制檯出錯Uncaught SyntaxError: Unexpected token К in JSON at position 0
我不明白,爲什麼我的代碼不起作用?
現在無法正常工作控制檯寫指數:1711遺漏的類型錯誤:無法讀取未定義 VM372的特性 'arrayToDataTable':231未捕獲的錯誤:不是一個數組 – Shato
你可以發佈代碼錯誤的地方,特別是「VM372:231」嗎? –