Chart math values 0-100% from a series of items

32 Views Asked by At

I have data $$a=12988, b=77, c=923, d=6494$$ for example

Trying to build a chart that represents a $0-100\%$ value but relative to the highest (a).

What calculations would I need to get this to plot correctly? (a) would be $100\%$ then (d) would be $50\%$ because it is half of (a). (b) would be a small percent but you can see it on the chart not so small it cant be seen. (linear)?

My output would be something like this:

<div class="grid">
    <div class="bar" style="--bar-value:100%;" data-name="a"></div>
    <div class="bar" style="--bar-value:2%;" data-name="b"></div>
    <div class="bar" style="--bar-value:30%;" data-name="c"></div>
    <div class="bar" style="--bar-value:50%;" data-name="d"></div>
</div>