html - javascript display multiple Highcharts using single function -


i trying display multiple highcharts on same webpage in different containers. know can copy , paste standard highcharts function bunch of time render many graphs page in different containers, since number of highcharts want display going depend on value extracted database (in example below number of charts equal @value) ideally want write 1 highcharts function, , loop on many times, in each iteration set chart options different. i've tried various permutations following code:

for (i = 0; <= <% @value %>; ++){     $(function (i) {        graphtitlearray = <% @markers.split(',') %>        graphtitle = graphtitlearray[i]        graphdata = <% @array[i].to_json %>        switch(i){           case 0:              containernum =  'container0'           case 1:              containernum = 'container1'            ...        }        $(containternum).highcharts({           title: {              text: graphtitle           }           series: [{                 name: 'something',                 data : graphdata             }]          //more options here        })     } } 

after trying type of strategy multiple times, can't graphs render or function recognize correct value of 'i'. know better way this? thanks!

i think selecting containers wrong. i've corrected below (assuming values such 'container0' id of container), including getting rid of non-needed case statement.

for (i = 0; <= <% @value %>; ++){    graphtitlearray = <% @markers.split(',') %>    graphtitle = graphtitlearray[i]    graphdata = <% @array[i].to_json %>     $('#container'+i).highcharts({       title: {          text: graphtitle       }       series: [{             name: 'something',             data : graphdata         }]      //more options here    }) } 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -