简体   繁体   中英

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:

<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. But when I run it on my ruby app it doesn't show the chart. I inspected the script in firebug and it doesn't enter when .enter() is called.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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