Wednesday, 14 August 2013

Pulling values from object in d3

Pulling values from object in d3

I am trying to use d3 for a simple visualization. I would like to pull the
values from the "dataset2" object and use them as rectangle heights. I am
receiving no error in the console, but a visualization is not appearing.
jsfiddle here: http://jsfiddle.net/GFyYk/
var dataset2 = {'foo': 50, 'bar': 40};
var d3data = d3.entries(dataset2)
var svg2 = d3.select('#test')
.append('svg')
.attr('width', 600)
.attr('height', 600)
svg2.append('rect')
.data(d3data)
.enter()
.append('rect')
.attr("x", function(d, i) {return i*21})
.attr('y', 0)
.attr('fill', 'brown')
.attr('width', 20)
.attr('height', function(d) {return d.value});

No comments:

Post a Comment