如何调试morris.js'找不到图形容器元素'错误

gra*_*ury 1 javascript ruby ruby-on-rails morris.js

我想显示一个morris.js图表

我的页面底部有以下内容.

<script src="/assets/raphael.js?body=1" type="text/javascript"></script>
<script src="/assets/morris.js?body=1"  type="text/javascript"></script>

<script type="text/javascript">
Morris.Line({
    element : 'line-example',
    data    : $('#averages-chart').data('averages'),
    xkey    : 'month',
    ykeys   : ['average'],
    labels  : ['Average']
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

但我在控制台中收到以下错误:

错误:未找到图形容器元素抛出新错误("未找到图形容器元素");

如果我在资产管道中加载javascript(但这会导致所有其他javascript不起作用),图形容器就在那里,因为它正确呈现.

请帮忙调试.

我也尝试过:

<script type="text/javascript">
$(window).bind("load", function() {
    Morris.Line({
        element : 'line-example',
        data    : $('#averages-chart').data('averages'),
        xkey    : 'month',
        ykeys   : ['average'],
        labels  : ['Average']
    });
});
</script>
Run Code Online (Sandbox Code Playgroud)

pra*_*ase 8

没有id为'line-example'的html div.添加它.该图表将显示在那里.