I have this data:
var bardata = [10, 16, 7, 19, 18, 16, 23, 36, 31, 26, 20, 19, 23, 9, 26];
And these buttons:
var data = [{ "label": "US", "text": "US" }, { "label": "Germany", "text": "Germany" },
{ "label": "UK", "text": "UK" }, { "label": "Average", "text": "Average" }];
var diventer = d3.select("#buttons").selectAll("div")
.data(data)
.enter().append("div")
.style("display", "inline")
.style("margin", "10px")
.attr("id", function(data) { return data.label; });
diventer.append("button")
.text(function(data) { return data.text; });
What kind of selector do I need to select every 3rd element in the bardata array, so that when I click a button I can highlight these bars on my graph?
This is what I currently have on mouseover, but I know it needs to be different for the buttons:
.on('mouseover', function(d) {
tooltip.transition()
.style('opacity', .9)
tooltip.html(d)
.style('left', (d3.event.pageX - 35) + 'px')
.style('top', (d3.event.pageY - 30) + 'px')
tempColor = this.style.fill;
d3.select(this)
.style('opacity', .5)
.style('fill', 'yellow')
})
I'm using the bardata here:
var myChart = d3.select('#chart').append('svg')
.style('background', '#E7E0CB')
.attr('width', width + margin.left + margin.right)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', 'translate('+ margin.left +', '+ margin.top +')')
.selectAll('rect').data(bardata)
.enter().append('rect')
bardata?