Hello everyone, I am hoping someone can help me with some math, because that is my weakness! I am working on the bar chart project, my first attempt at data visualization.
I have two linear scales for axes and the x and y coordinates of the bars. But the data is so large making the bar height go off the bottom of the chart. So I figured I needed a number to scale the heights of all the bars. But how do I calculate that number? By eye I have figured out 1/69.5 looks about right. Anything smaller and the bars don’t go down to the bottom axis. Anything larger and the bars are too long. But I don’t want to just hard-code it.
Maybe I am going about this all wrong. Or maybe I am using the linear scales incorrectly. Any guidance in the right direction would be very helpful!
It’s essentially: (max height a bar can have) / (max data value)
So when used to scale the heights, the bar for the max data value will have the max height.
Just because the last element in the array isn’t necessarily the largest, would it be better to use d3.max() instead? const barScale = (h-(paddingBottom+paddingTop))/d3.max(data, d=>d[1]);