2015-12-14 35 views
0

我試圖在flot圖表更新之前顯示加載框。在文檔加載它工作正常,但是當我使用按鈕上的點擊事件加載框只出現在更新後的圖表。在flot圖表生成之前顯示加載框

下面的文檔就緒作品。

function showLoadGraph() { 
    $("#loading-div-background").removeAttr('style'); 
    $("#loading-div-background").css({display:"block"}); 
    console.log("showLoadGraph"); 
} 

function hideLoadGraph() { 
    $("#loading-div-background").css({display:"none"}); 
    console.log("hideLoadGraph"); 
} 
$(document).ready(function() { 
    //api.loadActivityIndicator(); 
    //$("#loading-div-background").css({ opacity: 0.8 }); 

    showLoadGraph(); 
... 
$.ajax({ 
     url: 'flot_network_ajax.php', 
     type: 'GET', 
     data: 'action=network_availability&' + params, 
     dataType: 'json', 
     success: function(data) { 
      ajax_data = data.rows; 

      //process data 
      var availability_object = loopInitial(data.rows,"sevendays",""); 

      var json_object = calculateAvailability(availability_object); 

      rePlot(json_object); 
      api.hideActivityIndicator(); 
      hideLoadGraph(); 
      }, 
     error: function(e) { 
      //called when there is an error 
      console.log(e.responseText); 
     } 
    }); 

初始加載結束後,我嘗試在點擊事件上顯示加載框,但它只在flot更新後纔會更改。以下是放置在

我已經加入定時器來確認它正在很長doc.ready

//today click event 
    $("#group_period input").change(function(){ 
     showLoadGraph(); 
     var id = $(this).attr('id'); 
     var to = false; 
     if (id == "yesterday" || id == "lastmonth") 
      to = true; 
     var availability_object = loopInitial(ajax_data,id,to);  
     var json_object = calculateAvailability(availability_object); 
     rePlot(json_object); 
    }); 

更新。實際上它需要比圖表本身更長的處理圖表數據。如果我試圖表現出圖表數據處理之前裝載盒仍然沒有顯示

start sevendays process: 1450369631807 
Object {vfvftfvf: Array[0], vfvf: Array[0], tfvf: Array[0]} 
finish sevendays process: 1450369639141 
process sevendays duration : 7.334s 
start graph render: 1450369639141 
[Object] 
finish graph render: 1450369639179 
process graph render duration : 0.038s 
+0

提到你可能想看看他們支持的一些事件,plotclick和plothover的例子在這裏https://github.com/flot/flot/blob/master/API.md#customizing-the-grid,以及你可以在這裏掛鉤的東西:https:/ /github.com/flot/flot/blob/master/API.md#hooks ie bindEvents並繪製 – Pricey

+0

沒有一個正確的例子,所以我不知道如何做到這一點? – shorif2000

+0

查看掛鉤下面列出的代碼示例https://github.com/flot/flot/blob/master/API.md#hooks有一個函數hellohook(plot,canvascontext){alert(「hello! 「); }; var plot = $ .plot(placeholder,data,{hooks:{draw:[hellohook]}});'當「draw」事件發生時它將顯示一個警告框......有一個從1到8,大概你想要「設置數據」或「網格設置」類似的東西,並有一個功能,顯示覆蓋 – Pricey

回答