How to show "missing" rows in a rowChart using crossfilter and dc.js? -
How to show "missing" rows in a rowChart using crossfilter and dc.js? -
i'm using code similar in dc.js annotated example:
var ndx = crossfilter(data); ... var dayname=["0.sun","1.mon","2.tue","3.wed","4.thu","5.fri","6.sat"]; var dayofweek = ndx.dimension(function (d) { var day = d.dd.getday(); homecoming dayname[day]; }); var dayofweekgroup = dayofweek.group(); var dayofweekchart = dc.rowchart("#day-of-week-chart"); dayofweekchart.width(180) .height(180) .group(dayofweekgroup) .label(function(d){return d.key.substr(2);}) .dimension(dayofweek);
the issue i've got days of week nowadays in info displayed in rowchart
, , there's no guarantee every day represented in of info sets.
this desirable behaviour many types of categories, it's bit disconcerting omit them short , well-known lists day , month names , i'd rather empty row included instead.
for barchart
, can utilize .xunits(dc.units.ordinal)
, .x(d3.scale.ordinal.domain(dayname))
.
is there way same thing rowchart
days of week displayed, whether nowadays in info or not?
from understanding of crossfilter library, need @ chart level, , dimension ok is. i've been digging around in dc.js 1.6.0 api reference, , d3 scales documentation haven't had luck finding i'm looking for.
solution
based on @gordon's answer, i've added next function:
function ordinal_groups(keys, group) { homecoming { all: function () { var values = {}; group.all().foreach(function(d, i) { values[d.key] = d.value; }); var g = []; keys.foreach(function(key) { g.push({key: key, value: values[key] || 0}); }); homecoming g; } }; }
calling follows fill in missing rows 0s:
.group(ordinal_groups(daynames, dayofweekgroup))
actually, think improve off making sure groups exist before passing them off dc.js.
one way "fake group" pattern described here: https://github.com/dc-js/dc.js/wiki/faq#filter-the-data-before-its-charted
this way can create sure entries created every time info changes.
are saying tried adding entries ordinal domain , still weren't represented in row chart, whereas did work bar charts? that sounds bug me. specifically, looks back upwards ordinal domains needs added row chart.
dc.js crossfilter
Comments
Post a Comment