3👍
According to the graph, what you want is to start at (0,10) and then divide y
by 2 every time x
is incremented by 1.
Try this:
var time_data = [];
var value_data = [];
for (let i=0;i<=10;++i) {
time_data.push(i);
value_data.push(10/Math.pow(2,i));
}
This can be mathematically written as a decreasing exponential: 10 * 2^(-x)
or if you prefer 10 * exp(-ln(2) * x)
- [Chartjs]-ChartJS version 3 how to add percentage to pie chart tooltip
- [Chartjs]-Chart js v2 tooltip callback line breaks
0👍
If you’re looking for exponential decay, do you need to use Math.pow()
? What’s wrong with something like
left = left*factor
Where 0 < factor < 1
?
Looking at some documentation for Math.pow()
, the two arguments are base and exponent. In your example, left - 30^30
doesn’t make much sense because it will result in a vastly negative number and then default to 0.
An expression using Math.pow()
that will give the i
th term of an exponential decay sequence is
start_value * Math.pow(factor, i)
Where again, 0 < factor < 1
. The reduction in the value that you start with is compounded exponentially over each iteration.