...

View Full Version : Variable inside a javascript array



pkg123
06-25-2008, 12:37 PM
Hi,

I have a javascript array that draws a graph on the page.


var c = new Chart(document.getElementById('chart'));
c.setDefaultType(CHART_LINE);
c.setGridDensity(9, 5);
c.setVerticalRange(-40, 40);
c.setHorizontalLabels(['0', '5', '10', '15', '20', '25', '30','35','40' ]);
c.add('Change','#4040FF', [ 0, 10, 20, 10, 22, 32, 16, 14, 30]);
c.draw();

I'm trying to put variables into this array
c.add('Change','#4040FF', [ 0, 10, 20, 10, 22, 32, 16, 14, 30]);

so it will be


var pointa = 1*20;
c.add('Change','#4040FF', [ 0, "+pointa+", 20, 10, 22, 32, 16, 14, 30]);

However the above code doesn't work. Could some one help on this.

Thanks

Kor
06-25-2008, 02:26 PM
simply write the variable:


var pointa = 1*20;
c.add('Change','#4040FF', [ 0, pointa , 20, 10, 22, 32, 16, 14, 30]);

pkg123
06-25-2008, 02:44 PM
Hi Kor,

Thanks for getting back. Just hacked about and it does work. Cheers

Kor
06-25-2008, 03:16 PM
inside a javascript code only the string values are quoted.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum