javascript - How can I switch between JSON data sets in HighMaps using setData? -
i have highmap that's populated data fetched using getjson. want achieve have button (or dropdown) allows me switch between 2 or more data sets.
i've seen question asked few times in different ways (such this one), , reading answers think have general idea of need do, remain stuck. fwiw i'm complete novice trying make work colleagues, mistake might fundamental or matter of syntax.
for prove myself can make work i've tried implement button that, once clicked, switches second data set using setdata. while map displaying correctly, , know both json files being loaded, can't switch work.
here attempt in full: http://jsfiddle.net/osc9m3e7/4/
and part i'm sure incorrect somehow:
$('#setdata').click(function() { highcharts.mapchart.series[0].setdata(data1); }); i'd appreciate tips me on right track.
you have noticed how borders of countries getting thicker every time set new data. happens because data object not copied used directly, modified. copy specific object can use example slice() function. below can find example switching between sets of data works should.
api reference:
https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/array/slice
example:
http://jsfiddle.net/4ub0z408/
Comments
Post a Comment