简体   繁体   English

enter()d3.js在html.erb文件上不起作用

[英]enter() d3.js doesn't work on a html.erb file ruby rails

I'm trying to show a d3.js chart on a html.erb file this is the code: 我正在尝试在html.erb文件上显示d3.js图表​​,这是代码:

<div id="chart"></div>
    <script src="http://d3js.org/d3.v3.min.js"></script>
    <script type="text/javascript">
        d3.csv("app/views/incidentes/file.csv", function(data){

            var canvas= d3.select("#chart").append("svg")
                    .attr("width", 500)
                    .attr("height",500)
            canvas.selectAll("rect")
                    .data(data)
                    .enter()
                        .append("rect")
                        .attr("width", function(d){return d.cantidad*10;})
                        .attr("height", 50)
                        .attr("y", function(d, i){return i*50;})
                        .attr("fill", "blue")

        })



    </script>

It doesn't show the chart, I've made this code on a .html file and it goes well. 它没有显示图表,我已经在.html文件中编写了此代码,效果很好。 But when I run it on my ruby app it doesn't show the chart. 但是,当我在我的ruby应用程序上运行它时,它不会显示图表。 I inspected the script in firebug and it doesn't enter when .enter() is called. 我检查了Firebug中的脚本,并在调用.enter()时不输入脚本。

Script has not permissions to access view's path: 脚本无权访问视图的路径:

d3.csv("app/views/incidentes/file.csv" ..

Just, move 'file.csv' to '/public' folder, and replace file path with: 只需将“ file.csv”移动到“ / public”文件夹,然后将文件路径替换为:

 d3.csv("/file.csv" ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM