如果值等于零,如何隐藏dc.js行图值 [英] How can hide dc.js row chart values if values equal zero

查看:95
本文介绍了如果值等于零,如何隐藏dc.js行图值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过滤之后,如何在dc.js中隐藏行图值是否等于零?我们有这样的代码:

How can we hide if row chart values equal zero in dc.js after filtering .We have a code like this:

    var kurum=data.dimension(function(d){return ""+ d.KURUM;});
    var kurumGroup=kurum.group().reduceSum(function(d){return +d.INSIDANS});

    kurumRowMapChart
                    .width(300)
                    .height(200)
                    .margins({top: 5, left: 10, right: 10, bottom: 20})
                    .dimension(kurum)
                    .group(kurumGroup)
                    .colors(d3.scale.category10())
                    .elasticX(true)
                    .ordering(function(d) { return -d.value })
                    .xAxis().ticks(4);

此代码正常工作,但如果值等于零,我们希望在有过滤器时隐藏。

This code works normally but we want to hiding when has filter if values equal zero.

谢谢

推荐答案

您可以创建一个假组,删除包含以下内容的垃圾箱调用 .all()时为零:

You can create a "fake group" which removes the bins containing zeros when .all() is called:

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(kurumGroup);

kurumRowMapChart.dimension(kurum)
    .group(filtered_group)
    ...

https:// github.com/dc-js/dc.js/wiki/FAQ#remove-empty-bins

这个想法是创建一个位于两者之间的对象crossfilter和dc.js看起来像一个交叉过滤器组,并按需对其进行过滤。

The idea is to create an object which sits between crossfilter and dc.js which looks like a crossfilter group and filters it on demand.

这是一个有点复杂的示例,旨在测试不同数量的小节之间的过渡:

Here is a somewhat complicated example intended to test the transitions between varying numbers of bars:

http://dc-js.github.io/dc.js/ transitions / ordinal-row-transitions.html

(当前过渡效果不是很好,但它表明 remove_empty_bins 好。)

(Currently the transitions are not very good but it demonstrates remove_empty_bins well.)

这篇关于如果值等于零,如何隐藏dc.js行图值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆