2017-05-31 63 views
0

.Hi我一直在嘗試將google calendar chart添加到我的項目中,但有些問題我不明白。Google Chart long JavaScript問題

我的圖表在彈出式面板上,按鈕點擊觸發這裏是我的代碼;

點擊該按鈕功能:

function Detail(id) 
{ 
    google.charts.load("current", { packages: ["calendar"] }); 
    google.charts.setOnLoadCallback(drawChart); //callback for chart 
    $.ajax({ 
     //Some stuff here 
    }); 

    $.ajax({ 
     //Some other stuff here 
    }); 
} 

所以,你可以按鈕後,看到單擊drawChart必須運行。

function drawChart(){ 
    var dataTable = new google.visualization.DataTable(); 
    dataTable.addColumn({ type: 'date', id: 'Date' }); 
    dataTable.addColumn({ type: 'number', id: 'done/miss' }); 
    dataTable.addColumn({ type: 'string', role: 'tooltip', p: { html: true } }); 

    dataTable.addRows([ 
        [new Date(2017, 3, 9), 10, '<div style="width:40px; height:40px;">TESTtest</div>'] 
     ]); 
    var chart = new google.visualization.Calendar(document.getElementById('calendar')); 

    var options = { 
      title: "test", 
      height: '100%', 
     }; 
    chart.draw(dataTable, options); 
    $('#PopUpDiv').show(); 
} 

當我點擊了幾秒鐘和Firefox按鈕頁鎖說:「腳本停止工作或無響應了腳本:https://www.gstatic.com/charts ... sapi_compiled_format_module.js:179

的代碼看起來真的簡單而正確。我不明白髮生了什麼,所以一些幫助會很棒。提前致謝。

編輯:我已經創建了代碼剪切,並試試這個代碼,它的工作原理。現在我confuced :(

function Detail() 
 
{ 
 
google.charts.load("current", { packages: ["calendar"] }); 
 
    google.charts.setOnLoadCallback(drawChart); 
 
} 
 

 
function drawChart(){ 
 
    var dataTable = new google.visualization.DataTable(); 
 
    dataTable.addColumn({ type: 'date', id: 'Date' }); 
 
    dataTable.addColumn({ type: 'number', id: 'done/miss' }); 
 
    dataTable.addColumn({ type: 'string', role: 'tooltip', p: { html: true } }); 
 

 
    dataTable.addRows([ 
 
        [new Date(2017, 3, 9), 10, '<div style="width:40px; height:40px;">TESTtest</div>'] 
 
     ]); 
 
    var chart = new google.visualization.Calendar(document.getElementById('calendar')); 
 

 
    var options = { 
 
      title: "test", 
 
      height: '100%', 
 
     }; 
 
    chart.draw(dataTable, options); 
 
}
<script src="https://www.gstatic.com/charts/loader.js"></script> 
 
<button type="button" onclick="Detail()">click it</button> 
 
<div id="calendar"></div>

回答

0

我關上了VS並重新啓動該項目,並以某種方式問題解決了。因此,代碼是好的。謝謝大家的關注。