0
上午動態加載jqplot相應的文件,並將數據傳遞給和圖表div,但有時我得到的圖形和其他一些時間沒有得到圖形我的代碼如下我女傭ajax調用獲取價值觀和傳遞給目標ST圖形和輸出我得到如下所示請幫我運作Jqplot餅圖只渲染線條
jsFunction3(xyz) {
jQuery.getCSS = function(url, media)
{
jQuery(document.createElement('link')).attr({ href: url, media: media || 'screen', type: 'text/css', rel: 'stylesheet' }).appendTo('head'); };
$.getCSS('/redkanproject/plugins/jqplot-0.1/css/jqplot/jquery.jqplot.css','print');
$.getScript('/redkanproject/plugins/jqplot-0.1/js/jqplot/jquery.jqplot.min.js',
function() { }); $.getScript('/redkanproject/plugins/jqplot-0.1/js/jqplot/excanvas.min.js', function() { });
$.getScript('/redkanproject/plugins/jqplot-0.1/js/jqplot/plugin/jqplot.pieRenderer.min.js', function() { });
var JSONObject = new Object;
JSONObject.id =xyz;
JSONstring = JSON.stringify(JSONObject);
var url = "${createLink(controller:'page', action:'example4')}"; new Ajax.Request(url, { method:'post', contentType:'application/json', postBody:JSONstring, asynchronous:true, onSuccess: function (res) {
st=(res.responseJSON)
x="chart" // this is my div to display chart
var plot1 = $.jqplot (x, [st], { title: 'Bianual Reviews percentage', grid: {
background:'#834100', shadow: true,borderWidth: 0, borderColor: 'white',shadowDepth: 0}, seriesDefaults: {
// Make this a pie chart.
renderer: $.jqplot.PieRenderer, rendererOptions: {
// Put datalabels on the pie slices.
// By default, labels show the percentage of the slice.
sliceMargin:6,
showDataLabels: true
}
},
legend: { show:true, location: 'e' } });
$(x).bind('jqplotDataClick', function(ev,seriesIndex, pointIndex, data)
{ alert(" data: "+data); }
);
}
})//ajax }
------------------------------------------------------------------------
你真的希望有人來幫助你,當你離開格式化這樣的問題嗎? – Mark 2012-03-04 23:32:16
@Mark我編輯它整齊請你能幫我 – 2012-03-05 04:18:19
爲什麼你使用$ .getCSS和$ .getScript,爲什麼不加載資源jqPlot需要靜態。我認爲你在這裏有一點競爭條件。通過Ajax檢索CSS和JS文件,同時通過Ajax創建繪圖。這些都是異步請求,並不能保證JS和CSS將在劇情調用之前加載。 – Mark 2012-03-05 17:23:42