Hi, I am new to using Observable Plot, I’m looking to replace my Chart.js usage with this as it looks much nicer to use, however I’m stumbling at the first hurdle here.
I have a very simple bar chart created with Chart.js, it’s shown as a small chart on the page. It is the top bar chart in the screenshot.
My attempts to recreate this with Plot have so far made the bottom chart.
Changing the height manually helps, but ideally I don’t want to have to enter the height as I might have some charts with way more, I guess I have to calculate it by the number of items.
The padding doesn’t seem to do anything. I’ve increased the gaps with inset. Is there a way to have the bars in the grid lines rather than on them?
Plot draws an SVG at a specific size, either by choosing a size arbitrarily or by you specifying one. Then if you take that SVG and put it into a fixed size HTML area, it will scale up or down to fill the space. However, that means that things get squished, like you have seen. You either need to specify an exact size for Plot (by setting width and height in the plot function), or make the surrounding HTML expand to hold the generated SVG at it’s original size.
As for your question about grid lines: Plot’s grid lines align with the ticks on the axis. They are meant to help you trace your attention from the data to the axis, and aren’t meant as separators. In the chart Cobus posted, the y axis has been automatically detected as ordinal, aka ordered categories. You could change it’s type to linear instead, which is a type of continuous scale. When you do that, and fix a couple other things up, you end up with something like this:
You can see that there are some issues with the display here, like the bars being slightly vertically misaligned and the top most column being from 5.0 to 5.5. There are ways to fix that as well, but I’d suggest keeping the ordinal format that Cobus shared instead, since you are working with a ordinal data set and not a continuous one.