I had most of my D3 BarChart completed, but couldn’t access the dates for the data-date attribute, and to add to my tooltips. I had pulled the data from the json file and organized it as an array containing a gdp array and a date array, thinking I could match them by indices.
So I tried a different approach, and formed an array called barData of objects, each containing date and gdp. Now I can’t figure out how to access the data to even get the bars to show up. For instance, how would I referrence the correct data in the following?
barChart.append('g')
.attr('transform', 'translate(' + margin.left + ', 0)')
.selectAll('rect').data(barData)
.enter().append('rect')
.attr('class', 'bar')
.style('fill', '#05405e')
and
xScale = d3.scaleBand()
.domain(barData)
.paddingInner(0.1)
.paddingOuter(0)
.range([0, width]);
xAxisValues = d3.scaleTime()
.domain([barData[0].date, barData[(barData.length-1)].date])
.range([0, width]);
I have hunted all over for how to work with data in this format, but with no luck.