I'm trying to change the data set via a variable passed from the clicked button.
Here's an example of what I'm doing so far: http://jsfiddle.net/earlybirdtechie/qmC9E/
d3.selectAll('button.decadeBtn')
.on("click", function() {
var currentDecadeName = $(this).attr('data-decade');
console.log('currentDecadeName: '+ currentDecadeName);
svg.selectAll("rect.bars")
.data(currentDecadeName, function(d) { return d.id })
.transition()
.duration(1499)
.ease("bounce")
.attr({
height: function(d,i) {
return d.value;
}
})
In the jsFiddle example above when you click on any of the buttons, the bars should change based on the data for it's decade. Yet, the code is expecting the name of the data, not a dynamic variable name. So, if you go to line 43 in the js code and replace the variable name 'currentDecadeName' with 'seventies', then the bars will change to the seventies data once any button is clicked. How can I get this to work with a dynamic variable instead of a static data variable?
When I posted this question in google groups, I was told to use the map object, yet, I'm a noob and not clear on how d3.map works.
Can anyone clear up how one can use d3.map in this situation, or point me to a tutorial on how the map object works in d3?
Thanks!