首页 文章

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

提问于
浏览
3

我是 dc.jsd3.js 的新手 . 我创建了 bar chart 以及饼图和带有dc.js的折线图 .

现在,在条形图中,我希望 sort the bars 基于每个条形代表的值 . (例如,通过单击按钮 . )这是否可以使用dc.js?

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

1 回答

  • 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);
    

    重要的是:

    .ordering(function(t){return t.calls;})
    .cap(10);
    

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

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

相关问题