如何正确配置dc.js维度和组以显示数据元素

时间:2016-03-07 01:03:41

标签: dc.js

当我不断向我的数据集添加维度时,我遇到了一个问题,即我的条形图没有显示我的“帐户”维度的值。 这是我目前的小提琴:https://jsfiddle.net/eugene_goldberg/yv3nnred/18/

 var data = [
            {date: "2015-03-25T12:10:00", resolver: "Group 1",  escalation_pct: 20, bubble: 5,account: "Aon", region: "Americas", x: 1},
            {date: "2015-03-25T12:15:00", resolver: "Group 2",  escalation_pct: 10,  bubble: 5,account: "Boeing", region: "AMEA",  x: 1},
            {date: "2015-03-25T12:25:00", resolver: "Group 3",  escalation_pct: 50, bubble: 10,account: "Zurich", region: "Nordics", x: 1},
            {date: "2015-03-25T12:40:00", resolver: "Group 4",  escalation_pct: 30,  bubble: 1,account: "Aon", region: "Americas", x: 1},
            {date: "2015-03-25T12:35:00", resolver: "Group 5",  escalation_pct: 5, bubble: 10,account: "Boeing", region: "Australia", x: 1},
            {date: "2015-03-25T12:45:00", resolver: "Group 6",  escalation_pct: 13,  bubble: 1,account: "Zurich", region: "UK&I", x: 1}
        ];

var dimAccount = ndx.dimension(function(d) {return + d.account;});

    var accountGroup = dimAccount.group().reduceSum(function(d) {return d.x});

    var accountChart = dc.barChart("#account-chart");

    accountChart.width(480)
            .height(150)
            .dimension(dimAccount)
            .group(accountGroup)

            .x(d3.scale.linear().domain([0, 10]))
            .elasticY(true)
            .xAxis().tickFormat();

它必须是非常基本的东西,我还没有抓住它......

2 个答案:

答案 0 :(得分:2)

就我而言,使用行图是我需要的。 一个完全工作的小提琴如下:

https://jsfiddle.net/eugene_goldberg/yv3nnred/25/

var dimAccount = ndx.dimension(function(d) {return d.account;});

    var accountGroup = dimAccount.group().reduceSum(function (d) {
        return d.x;
    });

    var accountChart = dc.rowChart("#account-chart");

    accountChart

            .width(500)
            .height(500)
            .dimension(dimAccount)
            .group(accountGroup);

答案 1 :(得分:1)

行图很好用。但另一种选择是选择菜单,因为条形的高度并不代表任何你可以使用选项的简单下拉菜单。

(2.1分支dc.selectMenu