HorizontalBar Chart-II
In the last chapter we made horizontal Bar charts with axis. Today we will start by building a Bar chart with more than three data points.
We have a data set which has a type of fruit,total number of fruits and how many good ones out of the total.
const fruits = [
{ name: "🍊", count: 21, good: 12 },
{ name: "🍇", count: 13, good: 10 },
{ name: "🍏", count: 8, good: 5 },
{ name: "🍌", count: 5, good: 3 },
{ name: "🍐", count: 3, good: 1 },
{ name: "🍋", count: 2, good: 2 },
{ name: "🍎", count: 1, good: 1 },
{ name: "🍉", count: 1, good: 0 }
]So like the previous charts we can have one non continous scale and two linear scales. The name can be the band scale, count and good can be projected in linear scale.
As per my assumption, Since D3 and react gives a lot of freedom on svg manipulation so my idea will be to make two rectangle and project one top of another. So first create the same horizontal Bar from previous tutorial and then add good rectangle on top of count rectangle.
I doubt this is the best way of representing three data points on a chart. The Next thing is to add legend to tell about what the color means.
To add the legend I simply add a rectangle in the bottom right quadrant since I had the space there. I don't think the bar chart does a justice to the data though.