如何在 Rails 中包含 Flotr2 图表?
我试图在视图中包含图表,但它不起作用。有人可以帮忙吗?
这就是我的观点(flotr2.min.js 在 public/javascripts 中):
...
<div id="container">
<!--[if lt IE 9]>
<script type="text/javascript" src="/static/lib/FlashCanvas/bin/flashcanvas.js"> </script>
<![endif]-->
<%= javascript_include_tag "flotr2.min.js" %>
<script type="text/javascript">
(function () {
var d1 = [
[1, 10], [2, 8], [3, 5],[4, 13]],
d2 = [[1,12],[2,12],[3,12],[4,12],[5, 12]]
graph = Flotr.draw(container, [{data: d1, label: "Test"}, {data: d2, lines:{show: true}, points: {show: true}}], {
mode: 'time',
xaxis: {
ticks: [[1, "Jan"],[2, "Feb"], [3, "Mrz"], [4, "Apr"], [5, "Mai"], [6, "Jun"],
[7, "Jul"],[8, "Aug"], [9, "Sep"], [10, "Okt"], [11, "Nov"], [12, "Dez"]]
},
grid: {
minorVerticalLines: true,
backgroundColor: 'white'
}
});
})();
</script>
</div>
I'm trying to include a chart in a view, but it doesn't work. Can somebody help?
That's what I have in the view (flotr2.min.js is in public/javascripts):
...
<div id="container">
<!--[if lt IE 9]>
<script type="text/javascript" src="/static/lib/FlashCanvas/bin/flashcanvas.js"> </script>
<![endif]-->
<%= javascript_include_tag "flotr2.min.js" %>
<script type="text/javascript">
(function () {
var d1 = [
[1, 10], [2, 8], [3, 5],[4, 13]],
d2 = [[1,12],[2,12],[3,12],[4,12],[5, 12]]
graph = Flotr.draw(container, [{data: d1, label: "Test"}, {data: d2, lines:{show: true}, points: {show: true}}], {
mode: 'time',
xaxis: {
ticks: [[1, "Jan"],[2, "Feb"], [3, "Mrz"], [4, "Apr"], [5, "Mai"], [6, "Jun"],
[7, "Jul"],[8, "Aug"], [9, "Sep"], [10, "Okt"], [11, "Nov"], [12, "Dez"]]
},
grid: {
minorVerticalLines: true,
backgroundColor: 'white'
}
});
})();
</script>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可能需要修复你的容器大小,尝试在你的头脑中使用这种风格:
我还发现 github 上的当前版本不起作用。尝试 www.humblesoftware.com/static/js/flotr2.min.js
You might need to fix your container size, try having this style in your head:
I have also found the current version on github isnt working. Try www.humblesoftware.com/static/js/flotr2.min.js
您的脚本中缺少容器变量。在头部包含 flotr2.min.js 。容器必须具有正宽度:
尝试这样:
You are missing container variable in your Script. Include flotr2.min.js in the head. Container MUST have positive width:
Try it like that: