使用dc.js对条形图中的条进行排序

Don*_*ulk 3 sorting bar-chart d3.js crossfilter dc.js

我是dc.jsd3.js的新手.我创建了一个条形图以及饼图和带有dc.js的折线图.

现在,在条形图中,我想根据每个条形代表的值对条形图进行排序.(例如,通过单击按钮.)这可以用dc.js吗?

请注意,我设计了条形图,使得X轴表示地理位置,Y轴在某个值上缩放.

MSI*_*MSI 7

你能告诉我们一些代码吗?

在过去,我这样做了一个行图:

var topRowChart = dc.rowChart("#chart-top-dest");

topRowChart
.height(400)
.width(400)
.dimension(destination, "destination")
.group(calls,"calls")
.ordering(function(t){return t.calls;})
.label(function(d){ return d.key + " : " + d.value + " calls" ;})
.cap(10);
Run Code Online (Sandbox Code Playgroud)

重要的是:

.ordering(function(t){return t.calls;})
.cap(10);
Run Code Online (Sandbox Code Playgroud)

您必须将函数传递给ordering(),该函数返回将用于排序的维度/组.

令人惊讶的是,删除cap()会取消排序.