javascript - updating the array that is being passed to highcharts in meteor app -


i'm using meteor build dashboard uses highcharts build charts. current set follows. page loads show drop down menu. when user clicks drop down menu, client.js queries database based on selection, pushes results few global arrays followed blaze.render of template has chart. chart uses global variables series data , xaxis categories. problem when user selects different option drop down, arrays should updated , chart re-rendered. noticed array not populated new values. instead new values appended array.

code below:

  template.districtdropdown.events({ 'change #selectdistrict' : function(event, template){   // productvalues2.length = 0;   // productusage2.length = 0;   // productfidelity2.length = 0;   // productnames2.length = 0;   event.preventdefault();   var selectedvalue = template.$("#selectdistrict").val();   console.log("you selected " + selectedvalue);   var filter = {     find: {       'school district' : selectedvalue     }   };    $(filter).ready(function() {     meteor.subscribe('aggbydistrict', filter, function() {       productusage2 = [], productvalues2 = [], productfidelity2 = [];       productnames2 = _.uniq(combineddata.find().map( function(doc) { return doc.product; }));       for(var = 0; < productnames2.length; i++) {         productvalues2.push(combineddata.find({'product' : productnames2[i]}).count());         productusage2.push(combineddata.find({'product' : productnames2[i], 'usage' : {$gt:0}}).count());         productfidelity2.push(combineddata.find({'product' : productnames2[i], 'fidelity' :1 }).count());       };       console.log(productnames2, productusage2, productvalues2, productfidelity2);       // renders highchart shows various aggs selected district       blaze.render(template.licensesdistributedbydistrict, $("#licensesbydistrictcharts")[0]);     });   }); }   }); 

if uncomment productvalues2.length = 0 chart gets empty arrays.

i know a horrible implementation, i'm trying learn how use meteor / highcharts.

it's appending values because you're not clearing out existing values.

// productvalues2.length = 0; // productusage2.length = 0; // productfidelity2.length = 0; // productnames2.length = 0;

the code above clears arrays


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -