dc.js: Bar chart on subset of data

混江龙づ霸主 提交于 2020-12-13 12:15:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!