我正在嘗試使用Google API顯示折線圖。出於同樣的我試圖格式化從ASP.net WEBMETHOD的數據,如格式化數據以填充谷歌圖表
[WebMethod]
public static List<object> GetChartData()
{
List<object> chartData = new List<object>();
chartData.Add(new object[]
{
"DateTime", "Bugs"
});
chartData.Add(new object[]
{
"2011", "12",
"2014","45",
"2015","40",
"2016","98"
});
return chartData;
}
,這裏是我的客戶端代碼。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var options = {
title: 'Bug Tracker'
};
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetChartData",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var data = google.visualization.arrayToDataTable(r.d);
var chart = new google.visualization.LineChart($("#chart")[0]);
chart.draw(data, options);
},
failure: function (r) {
alert(r.d);
},
error: function (r) {
alert(r.d);
}
});
}
</script>
在運行上面的代碼我越來越喜歡0x800a139e - JavaScript runtime error: Row 0 has 8 columns, but must have 2
錯誤什麼是錯的,如何解決?
請WIRTE數據在Ajax響應harcoded也放到了小提琴,所以我們可以檢出 – mean
拉拉看我更新的答案,如果你得到了例如工作,然後在你的Ajax請求工作如果你無法正常工作,請回答一個問題。這裏試圖解決的因素太多了。 –
不要編輯一個問題,改變問題,當前無效答案http://meta.stackoverflow.com/questions/290297/how-much-change-to-the-question-is-too-much –