undefined不是函数 - Javascript中的错误

时间:2013-07-24 13:58:26

标签: javascript google-visualization

timechart = new google.visualization.Dashboard(document.getElementById('timechart'));

我得到undefined is not a function on this line。我在同一页面上初始化了其他图表,它们工作正常。作为参考,我的其余相关代码:

var timechartGraph = new google.visualization.ChartWrapper({
 'chartType': 'LineChart',
 'containerId': 'timechart-graph',
 'options': {
   // Use the same chart area width as the control for axis alignment.
  'legend': {'position': 'right'}

 },
 // Convert the first column from 'date' to 'string'.
 'view': {
   'columns': [
      {
       'calc': function(dataTable, rowIndex) {
         return dataTable.getFormattedValue(rowIndex, 11);
       },
       'type': 'string'
     },1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 }
 });

  var timechartRangeSlider = new google.visualization.ControlWrapper({
 'controlType': 'ChartRangeFilter',
 'containerId': 'timechart-range-slider',
 'options': {
   // Filter by the date axis.
   'filterColumnIndex': 11,
   'ui': {
     'chartType': 'LineChart',
     'chartOptions': {
       'hAxis': {'baselineColor': 'none'}
     },
     // Display a single series that shows the closing value of the stock.
     // Thus, this view has two columns: the date (axis) and the stock value (line series).
     'chartView': {
       'columns': [11, 12]
     },
     // 1 day in milliseconds = 24 * 60 * 60 * 1000 = 86,400,000
     //'minRangeSize': 86400000
   }
 },
 // Initial range: 2012-02-09 to 2012-03-20.
 //'state': {'range': {'start': new Date(2012, 1, 9), 'end': new Date(2012, 2, 20)}}
});

timechartData = new google.visualization.DataTable();

timechart = new google.visualization.Dashboard(document.getElementById('timechart'));
timechart.bind(timechartRangeSlider, timechartGraph);

1 个答案:

答案 0 :(得分:2)

如果你现在只加载核心图,你的代码可能看起来像这样:

google.load('visualization', '1', {
  'packages': ['corechart']
});

您还必须加载控件包,如下所示:

google.load('visualization', '1', {
  'packages': ['corechart', 'controls']
});

这应该定义google.visualization.Dashboard。