My goal is to have a barY chart scale down in height up to a certain point (eg. 500px) and then keep that as the min-height while allowing to further scale down in width.
This basically allows a chart to go from “wide” to “tall” which should make it better readable on mobile devices.
Is there a way to set min-height in Plot that I have overlooked?
I’ve been playing around for hours with this example but can’t replicate the behavior (getting a JS error about missing width) and the absolute / relative positioning isn’t working for me either.
Thanks @mcmcclur but I don’t think I was clear in my explanation.
What I’m looking for is a chart that scales when you resize the browser window. Yes, Plot does that by default. But the problem is that a chart can become very small in height. And what I’d like to have a min-height for a chart.
Update
Using Plot.plot({ width: Math.max(width, 550), … }) pretty much solved it for me. Found the solution over here.
Just setting a fixed height isn’t going to cut it. You want a starting height, and every chart has that by default anyway. But from there the height will scale down proportionally. So when you have a “wide” chart that might look fine on a desktop on mobile it will be tiny and most likely unreadable. At some point you want the chart to have a min-height and only scale the width. Does that make sense?
The solution that I quoted above pretty much does the trick.
Thanks, that’s an elegant solution as well in some cases!
When you have short and equal-length labels this works well (like in your chart) but it’s a challenge when labels are longer and different in length for instance country names.
Nevertheless, thanks for pointing this out and I didn’t realize that swapping axis could be done straight in Observable but makes sense.