Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Variable inside a javascript array

    Hi,

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

    Code:
    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
    Code:
    c.add('Change','#4040FF', [ 0, 10, 20, 10, 22, 32, 16, 14, 30]);
    so it will be

    Code:
    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    simply write the variable:
    Code:
    var pointa = 1*20;
    c.add('Change','#4040FF', [ 0, pointa , 20, 10, 22, 32, 16, 14, 30]);
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    pkg123 (06-25-2008)

  • #3
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Kor,

    Thanks for getting back. Just hacked about and it does work. Cheers
    Last edited by pkg123; 06-25-2008 at 01:56 PM.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    inside a javascript code only the string values are quoted.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •