簡體   English   中英

時間線圖表在Google Apps腳本中不起作用

[英]timeline charts not working in Google Apps Script

我正在嘗試使用Google Apps腳本中的Google Visualization API繪制一些圖表。 所有圖表都可以正常工作(PieChart,ComboChart ...),但可以使用時間表。

如果我將代碼復制/粘貼到HTML文件中,則可以正常工作,但是在Apps Script項目中,調用構建器時會拋出此錯誤(新的google.visualization.Timeline(container):“未定義不是函數”)。

這是我的代碼:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load('visualization', '1', {packages: ['corechart','timeline']});

    function pintarGraficaTimeline(){
     var chart = new google.visualization.Timeline(document.getElementById('divGrafica')); 
      var dataTable = new google.visualization.DataTable();

  dataTable.addColumn({ type: 'string', id: 'President' });
  dataTable.addColumn({ type: 'date', id: 'Start' });
  dataTable.addColumn({ type: 'date', id: 'End' });

  dataTable.addRows([
    [ 'Washington', new Date(1789, 3, 29), new Date(1797, 2, 3) ],
    [ 'Adams',      new Date(1797, 2, 3),  new Date(1801, 2, 3) ],
    [ 'Jefferson',  new Date(1801, 2, 3),  new Date(1809, 2, 3) ]]);

  chart.draw(dataTable);
 } 
</script>

</head>
<body style="font-family: Arial;border: 0 none;">
  <div id="divGraficaTimeline" style="float:right;display:block;">
   <div  style="float: right;"> <input type="button" value="Buscar" style="float:    right;margin-right: 4%;" onclick="pintarGraficaTimeline()" /></div>
</div>
<div id="divGrafica" > </div>

時間軸軟件包在Apps腳本中不起作用嗎?

時間軸包在Apps Script中尚不可用,盡管這不是問題,因為您沒有使用Apps Script驅動可視化。 這似乎可能是由於在API完成加載之前嘗試繪制圖表引起的。 嘗試在Google加載程序的回調中分配按鈕單擊事件:

function init () {
    var el = document.querySelector('#divGraficaTimeline input');
    if (document.addEventListener) {
        el.addEventListener('click', pintarGraficaTimeline);
    }
    else if (document.attachEvent) {
        el.attachEvent('onclick', pintarGraficaTimeline);
    }
    else {
        el.onclick = pintarGraficaTimeline;
    }
}
google.load('visualization', '1', {packages: ['corechart','timeline'], callback: init});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM