2017-04-06 45 views
1

我嘗試用谷歌的可視化圖表的圖表,當我點擊確定什麼也沒有發生,並且控制檯顯示錯誤:谷歌可視化:圖表編輯器錯誤

TypeError: a is not a function

我使用的代碼如下:

<script type="text/javascript"> 
google.load('visualization', '1', { packages: ['corechart', 'controls', 'charteditor'] }); 
google.setOnLoadCallback(drawChart); 
window.addEventListener('resize', redrawChart, false); 

var chart; 

function drawChart() { 
    var data = new google.visualization.DataTable(GetData()); 

    var columnsTable = new google.visualization.DataTable(); 
    columnsTable.addColumn('number', 'colIndex'); 
    columnsTable.addColumn('string', 'colLabel'); 
    var initState = { selectedValues: [] }; 
    // put the columns into this data table (skip column 0) 
    for (var i = 1; i < data.getNumberOfColumns(); i++) { 
     columnsTable.addRow([i, data.getColumnLabel(i)]); 
     // you can comment out this next line if you want to have a default selection other than the whole list 
     initState.selectedValues.push(data.getColumnLabel(i)); 
    } 
    // you can set individual columns to be the default columns (instead of populating via the loop above) like this: 
    // initState.selectedValues.push(data.getColumnLabel(4)); 

    chart = new google.visualization.ChartWrapper({ 
     chartType: 'LineChart', 
     containerId: 'chart_div', 
     dataTable: data, 
     options: { 
      title: 'Number In Treatment' 
     } 
    }); 

    var chartEditor = new google.visualization.ChartEditor(); 
    google.visualization.events.addListener(chartEditor, 'ok', data); 
    chartEditor.openDialog(chart, {}); 
    chart = chartEditor.getChartWrapper(); 
    redrawChart(); 

    var columnFilter = new google.visualization.ControlWrapper({ 
     controlType: 'CategoryFilter', 
     containerId: 'filter_div', 
     dataTable: columnsTable, 
     options: { 
      filterColumnLabel: 'colLabel', 
      ui: { 
       label: 'Columns', 
       allowTyping: false, 
       allowMultiple: true, 
       allowNone: false, 
       selectedValuesLayout: 'belowStacked' 
      } 
     }, 
     state: initState 
    }); 

    var width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0) + 'px'; 

    chart.setOption('height', '200px'); 
    chart.setOption('width', width); 

    setChartView(); 

    function setChartView() { 
     var state = columnFilter.getState(); 
     var row; 
     var view = { 
      columns: [0] 
     }; 
     for (var i = 0; i < state.selectedValues.length; i++) { 
      row = columnsTable.getFilteredRows([{ column: 1, value: state.selectedValues[i] }])[0]; 
      view.columns.push(columnsTable.getValue(row, 0)); 
     } 
     // sort the indices into their original order 
     view.columns.sort(function (a, b) { 
      return (a - b); 
     }); 
     chart.setView(view); 
     chart.draw(); 
    } 


    google.visualization.events.addListener(columnFilter, 'statechange', setChartView); 

    setChartView(); 
    columnFilter.draw(); 
} 

function redrawChart() { 

    var width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0) + 'px'; 

    chart.setOption('height', '200px'); 
    chart.setOption('width', width); 

    chart.draw(); 
} 

如何獲得一次OK按鈕被點擊的圖表被重繪?

+0

嘗試用開發版本替換縮減版本的谷歌可視化libaray,這會使您獲得更具描述性的錯誤消息。 –

+0

谷歌可視化庫的開發版本的鏈接是什麼 – CryoFusion87

+0

您能否將您的所有'