amitkaps
10/5/2015 - 9:58 PM

Bar_d3js+svg.html

<!DOCTYPE html>

<script src="../lib/d3.min.js"></script>

<svg id="chart"></svg>

<script>

var data = [5, 25, 15, 20, 10];

var width = 250,
    height = 200,
    barHeight = 25;
    margin = 5;

var x = d3.scale.linear()
    .domain([0, d3.max(data)])
    .range([0, width]);

var chart = d3.select("#chart")
    .attr("width", width)
    .attr("height", height)
    .attr("fill", "brown");

var bar = chart.selectAll("rect")
    .data(data)
  .enter().append("rect")
    .attr("x", 0)
    .attr("y", function(d, i) {
      return i * (barHeight + margin); })
    .attr("width", x)
    .attr("height", barHeight);

</script>