问题
I have data in format
[
{ "date": dt1, "action": "T", "isRequest": "", "delay": 0 },
{ "date": dt1, "action": "C1", "isRequest": "R", "delay": 10 },
{ "date": dt1, "action": "T", "isRequest": "", "delay": 0 },
{ "date": dt1, "action": "C2", "isRequest": "R", "delay": 20 },
{ "date": dt1, "action": "T", "isRequest": "", "delay": 0 },
... ]
Main bar chart is about counts (1 line in array), all delays chart is about delay distribution (attribute delay)
Filtering by date main graph, changes data on all delays chart.
So far, so good.
Now, I want an another chart that works with subset of data in all delays chart, taking into account filter for attribute "action": "C1".
I could filter original data and call crossfilter(filteredData)
, but than filtering on main graph would not reflect on data in this chart.
I have tried to get inspiration from Crossfilter dimension and group to filter out data below certain threshold
Example is on
http://jsfiddle.net/iracic/dtyeL7g7/5/
Thank you
回答1:
You would want to implement a filter in a custom group so that the group only aggregates records that meet your criteria. You can use a helper library like Reductio to do this and would build your group something like:
var dim = ndx.dimension(...);
var group = reductio().count(true)
.filter(function(d) { return d.action === "C1"; })(dim.group());
Example in the documentation here: https://github.com/crossfilter/reductio#aggregations-standard-aggregations-reductio-b-filter-b-i-filterfn-i-
It is also possible to do this directly using custom groups, but it's a bit complex.
Unrelated: group.reduceCount doesn't take a parameter, so the functions you are passing to it in your example aren't doing anything.
来源:https://stackoverflow.com/questions/37641350/dc-js-bar-chart-on-subset-of-data