I created a custom aggregate function that captures the average of values 
in my table that are greater than 0...

function avgNonZero(values) {
  avgNonZero=0;
  var total=0;
  var j=0;
  for (var i = 0; i < values.length; i++){
     if(values[i]>0){
        total += values[i];
        j=j+1;
     }
  } 
  if(j>0){avgNonZero=total/j;}
  return Math.round(avgNonZero);
}

It works and I call it from the initial drawVisualization function when I 
need to group my datatable. However...

I recently added code to  call it again when the user specifies a date 
range. I filter my datatable by date, then group again to re-average.  This 
time the aggregation fails because avgNonZero returns the value of the 
average rather than the function.

I thought perhaps this has to do with the way I have declared the function 
or scope - not sure.  I tried declaring the function this way

var avgNonZero = function(values) { ...}

but the same thing happens.


Is there a specific way I should declare my custom aggregate function ???

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-visualization-api/-/K6SNg_V4VQwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to