I'm trying to construct a highcharts barchart using data from multiple locally held json files and having a bit of trouble. For simplicity's sake I want to loop through all files, do a search for a particular string and use the count as the data for my graph. I've went about it like so:
options.series[0].name = 'Test';
options.series[0].data = [];
//Loop over the different local files and do a search count in each
var localfiles = new Array('localfile1.json', 'localfile2.json');
for (var i=0; i<locfiles.length; i++) {
//do a count here
$.getJSON(localfiles[i], function(data) {
var count = 0;
var index = 0;
var entry;
for (index = 0; index < data.length; ++index) {
entry = data[index];
if (entry.searchkey == "searchstring") {
count ++;
}
options.series[0].data.push(count);
});
});
var chart = new Highcharts.Chart(options);
I realise that I'm not passing the options array around correctly. But I'm not sure what way I should code this. Any advice?
Thanks in advance.