.elasticX(true) 不起作用 dc.js

.elasticX(true) doesn't work dc.js

我有一个复合线图

.elasticX(true) 不起作用:/有人能帮我吗

var composite = dc.compositeChart("#durationline-chart");
    composite.width(1500).height(350)
        .group(Durations)
        .brushOn(true)
        .yAxisLabel("Duration")
        .x(d3.scale.ordinal())
        .xUnits(dc.units.ordinal)
        .margins({ top: 10, left: 50, right: 10, bottom: 50 })
        .elasticY(true)
        .elasticX(true)
        .renderlet(function(chart) {
                chart.selectAll("g.x text")
                    .attr('transform', "rotate(+20)");
            })
        .compose([
            dc.lineChart(composite)
                .group(Testcase_Time, "Time")
                .colors('#1E90FF'),
            dc.lineChart(composite)
                .group(Testcase_Smartkey, "Smartkey")
                .colors('red')]);

编辑:这是 jsfiddle:https://jsfiddle.net/gordonwoodhull/o9xx3fmm/

我想你的意思是当图表被过滤时弹性没有启动。

这是因为 crossfilter 仍然 returns bins 如果它们是空的 - 它们只是值为零。所以 dc.js 仍然检测所有 bin 的域,包括空的。

你可以做的是使用一个假的组来删除空垃圾箱

function remove_empty_bins(source_group) {
    return {
        all:function () {
            return source_group.all().filter(function(d) {
                return d.value != 0;
            });
        }
    };
}


var filtered_group = remove_empty_bins(group);

chart.dimension(dim)
    .group(filtered_group)
    ...

然后dc.js将只检测非零值域。更多详情 in the FAQ.

您必须将此应用于构成图表的所有组。