SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Many Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Try this:

    var pointa = 1*20;
    c.add('Change','#4040FF', [ 0, pointa, 20, 10, 22, 32, 16, 14, 30]);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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