How can hide dc.js row chart values if values equal zero

前端 未结 2 859
情深已故
情深已故 2020-12-21 05:02

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.KU         


        
相关标签:
2条回答
  • 2020-12-21 05:22

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

    using it like this:

    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

    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

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

    0 讨论(0)
  • 2020-12-21 05:29

    @Gordon: Great answer! remove_empty_bins() worked for me! :)

    I had to use d.value.count instead of d.value but I assume this depends on which group-reduce function you are using:

    return d.value.count !== 0;
    
    0 讨论(0)
提交回复
热议问题