javascript - how do you create muliple charts with the same options but with different data -
i draw multiple charts on 1 page using same options different json data each chart. little code possible, need omit code duplication.
here example of first chart:
$(function() { $.getjson('login.php', function(data) { var options= { chart : { renderto : 'container' }, rangeselector : { enabled:false }, series : data }; var chart = new highcharts.stockchart(options); }); });
how use above code create multiple charts using different getjson data?
you create helper function:
$(function() { var genoptions = function(data) { return { chart : { renderto : 'container' }, rangeselector : { enabled:false }, series : data }; }; $.getjson('login.php', function(data) { var options = genoptions(data); var chart = new highcharts.stockchart(options); }); $.getjson('secondpage.php', function(data) { var options = genoptions(data); var chart = new highcharts.stockchart(options); }); });
Comments
Post a Comment