I'm currently trying to integrate d3 with my rails app. After installing the d3-rails gem, I came across this tutorial on d3. Somewhere in the tutorial, the below code is provided
<meta charset="utf-8">
<style>
.chart div {
font: 10px sans-serif;
background-color: steelblue;
text-align: right;
padding: 3px;
margin: 1px;
color: white;
}
</style>
<div class="chart"></div>
<script>
var data = [4, 8, 15, 16, 23, 42];
var x = d3.scale.linear()
.domain([0, d3.max(data)])
.range([0, 420]);
d3.select(".chart")
.selectAll("div")
.data(data)
.enter().append("div")
.style("width", function(d) { return x(d) + "px"; })
.text(function(d) { return d; });
</script>
If I were to include the above code as it is into my new.html.erb file, the chart will show.
I then created a new graph.js fiel under app/assets/javascripts and decided to put everything between the <script> </script> tag inside graph.js. Now when I open up new.html.erb, the chart will not show anymore.
Am I doing something wrong here that's causing rails to not recognize graph.js ?
/scripts/application.jsand examine ifd3code has been included. Second thing is to open the developer console of the browser and examine for potential exceptions with JavaScript code.