dimanche 3 mai 2015

D3 barchart not populating.

I am trying to create a bar-chart using D3. However, the bar chart is not populating. The following is my code:

 var data = [Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random()]

var height = 900 
var width = 600 

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

var y = d3.scale.linear()
    .range([height, 0])
    .domain([0, 500])

var svg = d3.select(".barchart").append('svg')
    .attr("height", height)
    .attr("width", width)    

var rect = svg.selectAll('rects')
    .data(data)
    .enter()
    .append('rects')
    .attr("height", function(d, i) { return height - y(d) })
    .attr("width", function (d, i) { return x(d) })
    .attr("x", function(d, i) { return x(i) })
    .attr("y", function(d, i) { return y(d) })
    .attr("fill", "blue")




Aucun commentaire:

Enregistrer un commentaire