This isn’t going to be one of those barcharts you’ve seen on TV, what with tick marks and hover effects and such. This one’s just some bars, some labels and a baseline. It will, however, come with some useful features to help us reuse it.
This Svelte component’s pretty basic, though. What else is it missing?
The height and width are configurable, and the bars resize in response to them, but their CSS transitions are slow to catch up. Ideally we’d have the bars apply the transition when they resize because of a change in data but not in response to a change in chart height or width.
We have no axes other than the baseline. That’s fine for a lot of uses, but we might want to add those elements for other uses.
We could add those elements manually, but the d3-axis package has some helpers for creating axes quickly!
The bars are all the same colour. We could write a function that converts each bar’s data value to a colour, and use it for the <rect>fill attribute, but the d3-scale-chromatic also has some helpers to do this quickly!