Search code examples
if-statementsvggraphael

If/else statement on raphael g.barchar


Hi i have a bar chart made with g.raphael

The 47 in brackets in bold i am looking to place an if else statement in there. it seems to cause errors if i do so. Any help?

paper.barchart(-5, -20, 480, 260, [(47), 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52], {colors:["RGB(45,58,65)","RGB(217,31,53)","RGB(217,31,53)","RGB(217,31,53)","RGB(217,31,53)","RGB(217,31,53)","RGB(205,148,43)","RGB(205,148,43)","RGB(205,148,43)","RGB(205,148,43)","RGB(73,102,20)","RGB(73,102,20)","RGB(73,102,20)","RGB(73,102,20)","RGB(73,102,20)","RGB(0,99,186)","RGB(0,99,186)","RGB(0,99,186)","RGB(0,99,186)"]})


Solution

  • I've never tried a nested if block there, but you can define your data array outside of the instantiation, using if statements to build that according to your conditions, and then using your array variable in the call:

    var dataArray  = [...];
    var colorArray = [...];
    paper.barchart(-5, -20,
                   480, 260,
                   dataArray,
                   {
                       colors : colorArray
                   });