My JSON file is external and has a specific structure:
{
data: [
{
0: 'cat',
1: 232,
2: 45
},
{
0: 'dog',
1: 21,
2: 9
},
{
0: 'lion',
1: 32,
2: 5
},
{
0: 'elephant',
1: 9,
2: 4
},
]
}
With d3.js, my goal is to extract the height data using key 2 for a bar chart. Here's what I have set up:
d3.select('#chart').append('svg')
.selectAll('rect')
.data(data)
.enter()
.append('rect')
.attr('width', barWidth)
.attr('height', function(d) {
return d.data['2'];
});
I can see the SVG canvas but am struggling to display the rectangles for the bar chart height. Any suggestions?
Appreciate any help!