user3003490
user3003490

Reputation: 27

Canvas HTML5 datapoints to arrays

I hope someone can guide me on how to convert long data points into arrays as i have a long list to plot and i hope of an easier way to loop instead of typing x 50 times.

Currently, i have data points where x increment of +.25 and y is calculated from a formula below.

Example:

dataPoints: [
{ x: 0, y: 1000*(0.5/(50*0.6))* (Math.exp(-((6)/(50*0.6)*0))) }
];

Link to demo: http://jsfiddle.net/QwZuf/95/

Thank you!

Upvotes: 0

Views: 987

Answers (1)

Alnitak
Alnitak

Reputation: 339816

You just need a simple for loop:

var dataPoints = [];

for (var x = 0; x <= 12.5; x += 0.25) {
    dataPoints.push({ 
        x: x,
        y: 1000*(0.5/(50*0.6))* (Math.exp(-((6)/(50*0.6)*x)))
    });
}

and then pass that array as the dataPoints parameter to the plotting function.

See http://jsfiddle.net/alnitak/xQpv7/

Upvotes: 1

Related Questions