As3adTintin
As3adTintin

Reputation: 2476

dc.js Number Display Widget

I'm new to dc.js... and honestly have little clue what's going on with the number display widget. I tried looking at the example and essentially copied sections of it verbatim into my code hoping it would work (but knowing it wouldn't). My goal is to display the average of a line graph (sat scores) (that would change based on the crossfilter). Any suggestions?...

var ndx = crossfilter(csv);
var all = ndx.groupAll();
var bysat = ndx.dimension(function(d) { return d.compositesat; });

var boxND = dc.numberDisplay("#number-box");

var satavgnum = bysat.group().reduce(
          function (p, v) {
              ++p.n;
              p.tot += v.compositesat;
              return p;
          },
          function (p, v) {
              --p.n;
              p.tot -= v.compositesat;
              return p;
          },
          function () { return {n:0,tot:0}; }
      );

var average = function(d) {
    return d.n ? d.tot / d.n: 0; };

boxND
    .formatNumber(d3.format(".3s"))
    .valueAccessor(average)
    .group(satavgnum);

Upvotes: 0

Views: 1504

Answers (1)

Gordon
Gordon

Reputation: 20120

"It doesn't work." What result are you getting? 0? NaN? Blank?

If you're seeing a result but it's wrong, it's time to pull out the debugger and see what's wrong with the data. There are a couple of tips here:

https://github.com/dc-js/dc.js/wiki/FAQ#tell-whether-my-groups-are-functioning-correctly--whether-my-input-data-is-good

If you're not getting any result, try putting some initial text into the #number-box div, and seeing if it gets overwritten.

Indeed it looks like you've copied and pasted examples/number.html pretty faithfully, and it would be hard to say what's going wrong without a fiddle or at least an example of the data.

Upvotes: 2

Related Questions