Uniformly-spaced histogram bins with dc.js?

不问归期 提交于 2021-01-27 06:38:25

问题


Mike Bostock uses the following snippet to generate uniformly-spaced bins for a histogram:

var data = d3.layout.histogram()
.bins(x.ticks(20))
(values);

source

Is there any way to adapt this to a project that uses dc.js and crossfilter.js?

Essentially, I want to dynamically generate the bins and then use the chart to filter on a particular attribute. Total newbie to this. Any guidance would be appreciated!


回答1:


dc.js supports histograms via crossfilter. Use a group for your bar chart that looks something like this:

var binwidth = 0.2;
var dim = ndx.dimension(function(d) { return d.x; });
var group = dim.group(function(d) { return binwidth * Math.floor(d.x/binwidth); });

This tells crossfilter to use keys binwidth apart.

And initialize the bar chart with these units:

chart.xUnits(dc.units.fp.precision(binwidth));


来源:https://stackoverflow.com/questions/29438515/uniformly-spaced-histogram-bins-with-dc-js

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