未捕获的TypeError:对象[object Object]在Highcharts中没有方法'getElementsByTagName'

时间:2013-12-26 22:24:05

标签: javascript highcharts

我正在尝试显示一个简单的图表,我正在导入以下文件(我使用的是Highcharts 3.0.7):

highcharts.js
data.js
exporting.js

我正在尝试根据表格绘制图表。这是表格:

<table id="datatable">
    <thead>
        <tr>
            <th></th>
            <th>Jane</th>
            <th>John</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th>Apples</th>
            <td>3</td>
            <td>4</td>
        </tr>
        <tr>
            <th>Pears</th>
            <td>2</td>
            <td>0</td>
        </tr>
        <tr>
            <th>Plums</th>
            <td>5</td>
            <td>11</td>
        </tr>
        <tr>
            <th>Bananas</th>
            <td>1</td>
            <td>1</td>
        </tr>
        <tr>
            <th>Oranges</th>
            <td>2</td>
            <td>4</td>
        </tr>
    </tbody>
</table>

这是javascript:

$(function() {
  return $("#container").highcharts({
    data: {
      table: $("#datatable")
    },
    chart: {
      type: "column"
    },
    title: {
      text: "Data extracted from a HTML table in the page"
    },
    yAxis: {
      allowDecimals: false,
      title: {
        text: "Units"
      }
    }
  });
});

如您所见,它与此处的示例几乎相同:

http://www.highcharts.com/demo/column-parsed

但是,我从data.js收到以下错误:

Uncaught TypeError: Object [object Object] has no method 'getElementsByTagName'

不显示任何条形图,但绘制了画布。我怎样才能解决这个问题?感谢

2 个答案:

答案 0 :(得分:2)

更改您的代码
data: {
  table: $("#datatable")
},

data: {
  table: document.getElementById('datatable')
},

Fiddler Demo here

答案 1 :(得分:1)

将您的代码更改为 FIDDLE

    data: {
        table: $('#datatable')[0]
    },