与dc.js均匀分布的直方图箱? [英] Uniformly-spaced histogram bins with dc.js?
问题描述
Mike Bostock使用以下代码段为直方图生成均匀分布的bin:
Mike Bostock uses the following snippet to generate uniformly-spaced bins for a histogram:
var data = d3.layout.histogram()
.bins(x.ticks(20))
(values);
有什么方法可以使其适应使用dc.js和crossfilter.js的项目?
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!
推荐答案
dc.js通过交叉过滤器支持直方图.为您的条形图使用一个看起来像这样的组:
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));
这篇关于与dc.js均匀分布的直方图箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!