javascript morris.js 图形容器元素未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18176755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
morris.js Graph container element not found
提问by Gene Bo
回答by Gene Bo
Solution:Put the javascript after the morris.js div
解决方案:将javascript放在morris.js div之后
From this post from tiraeth: https://github.com/morrisjs/morris.js/issues/137
来自 tiraeth 的这篇文章:https: //github.com/morrisjs/morris.js/issues/137
回答by Anatole Nkwadjo
if don' t use the chart on this page, you can do this:
如果不使用此页面上的图表,您可以这样做:
- Go to the line where the exception is throwed in morris.js
change it like this: before:
if (this.el === null || this.el.length === 0) { return; // throw new Error("Graph placeholder not found."); }
- 转到morris.js中抛出异常的那一行
像这样改变它:之前:
if (this.el === null || this.el.length === 0) { return; // throw new Error("Graph placeholder not found."); }
回答by rjs6502
I had this issue when I was using the node.js framework. Taking out the script tags containing the morris charts and the jquery from the bottom of the html file worked for me. I am using Require.js to load the dependencies for my project instead. I hope this helped.
我在使用 node.js 框架时遇到了这个问题。从 html 文件的底部取出包含莫里斯图表和 jquery 的脚本标签对我有用。我正在使用 Require.js 来加载我的项目的依赖项。我希望这有帮助。
回答by Milind Babar
Try This
试试这个
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://cdn.oesmith.co.uk/morris-0.4.1.min.js"></script>
</head>
<body>
<div id="donut-example"></div>
<script type="text/javascript">
Morris.Donut({
element: 'donut-example',
data: [
{ label: "Download Sales", value: 12 },
{ label: "In-Store Sales", value: 30 },
{ label: "Mail-Order Sales", value: 20 }
]
});
</script>
</div>
</body>
回答by Panchal Deep
JavaScript's code gets executed before the DOM contains #annual element. Put the javascript after the div or use jQuery.ready()
JavaScript 的代码在 DOM 包含 #annual 元素之前执行。将 javascript 放在 div 之后或使用 jQuery.ready()