You will have to forgive the wording of this question, I am sure that there is a better, more concise way to ask about it, but I do not know this.
Say I have a graph and all the y axis values
[0,4,5,3,2,5,6]
The maximum value is six. Therefore, I would like the Y-scale to be labeled from 0 to 10.
Given the following values
[33,26,54,23,86,23]
The maximum value is 86, so I would like the Y-scale to run from 0 to 90.
Now let's say that I have the following values
[98,253,87, 876,263]
The maximum is 876, so the Y scale should go from 0 to 900
Now I have created the following function, which should give me all the max y-scale values ββthat I need so far.
function padMaxValue(value){ for(var i = 1; i < 1000000000000000000; i = i * 10){ var decimalValue = value / i; if(value === i){ return i; } if(decimalValue < 1 && decimalValue > 0.09){ return i; } } }
However, given the following values
[99,123,82,189,45]
My function would set max. max at 1000 . But max should really be 200. I understand that I really need a smart way to increase the value of i instead of just multiplying it by 10. I need to be able to increase the value of i by 10, all the way to 100. Then increase it by 100, right up to 1000. Then increase it by 1000, up to 10 000 and so on.
I feel that there must be some neat and tidy mathematical way to do this. And I also feel that the number 1000000000000000000 that I have in the for loop betrays my ignorance of mathematics.
Anyhoot, this problem. Any ideas?
javascript math max
gargantuan Oct 30 '14 at 19:48 2014-10-30 19:48
source share