方式一:setJSONUrl
function initChart() {
var myChart = new FusionCharts("FusionCharts/Line.swf", "myChartId", "100%", "100%", "0", "1");
var url = '${pageContext.request.contextPath}/enterleaveinfoAction!realtimeCarEnterinfoChart.action?carDate=2013-0=11-28';
myChart.setJSONUrl(url);
myChart.render("chartContainer");
}
问题:第一次页面加载没问题,后续刷新时会出现 no data to display,据说是跟渲染没完成重新请求数据有关。
方式二:setJSONData
function initChart() { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "${pageContext.request.contextPath}/enterleaveinfoAction!realtimeCarEnterinfoChart.action?carDate=2013-0=11-28", data: "{}", dataType: 'json', success: function (json) { var myChart = new FusionCharts("FusionCharts/Line.swf", "myChartId", "100%", "100%", "0", "1"); myChart.setJSONData(json); myChart.render("chartContainer"); }, error: function (xhr) { //如果没有上面的捕获出错会执行这里的回调函数 alert('页出错 ' + xhr.responseText); } }); }