我正在尝试使用 JSON 创建一个浮点饼图。在静态数据中,它工作正常,但是当我想动态发送数据(使用 JSON)时,什么都没有显示。这是我的代码:
<script src="jquery-1.11.2.min.js"></script>
<script src="jquery.flot.js"></script>
<script src="jquery.flot.pie.js"></script>
....
$.ajax({
url: 'PieChart.aspx/GetData',
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: 'json',
success: function (data) {
//alert("should be shown");
$.plot($("#placeholder"), data, {
series: {
pie: {
show: true
}
},
legend: {
labelBoxBorderColor: "none"
}
});
},
failure: function (response) {
alert(response.d);
}
});
Asp.net server_side 中的代码:
[System.Web.Services.WebMethod]
public static string GetData()
{
//there are some other codes here, just to test. I've replaced them using this line.
return "[{ label: \"IE\", data: 19.5, color: \"#4572A7\" }, { label: \"Safari\", data: 4.5, color: \"#80699B\" }]";
}
需要帮忙。谢谢