dc.js饼图图例-如果结果为0,则隐藏 [英] dc.js piechart legend - hide if result is 0

查看:85
本文介绍了dc.js饼图图例-如果结果为0,则隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果结果为0,是否可以删除/隐藏饼图的图例?



我有一个图例中有很多项目的饼图,



任何帮助将不胜感激。

解决方案

图例在重绘图表时会进行渲染,但是这里的问题是图例是从数据中绘制的,并且交叉过滤器不会自动消除空的组。 p>

如果图例是图表类型,那就太好了,因此我们可以使用假组(也称为数据转换)。但是不,我们需要更新 .legendables()来过滤出空箱:

  dc.override(pieactChart,'legendables',function(){
var legendables = this._legendables();
返回legendables.filter(function(l){
返回l.data> 0;
});
});

小提琴的叉子: http://jsfiddle.net/gordonwoodhull/13t804u6/5/



注意:这只会修改一个(左)图表,您必须为每个图表复制/粘贴(或将其包装在函数中)以将其应用于其他图表。



[我是不想在图表中进行此类数据筛选非常固执,因此我不建议您将此功能用作功能。相反,图例应该是一个从另一个图表中获取其数据的图表,并且应该有一种转换该数据的方法。]


Is it possible to remove/hide the legends for a piechart if the result is 0?

I have a piechart that has quite a few items in the legend, when there has been some filtering it would be great to remove the legends that are not available.

Any help would be appreciated.

解决方案

Legends do render when their charts are redrawn, but the problem here is that the legend is drawn from the data, and crossfilter doesn't automatically eliminate empty groups.

It would be really great if legends were a chart type, so we could just use a fake group (a.k.a. "data transform"). But no, we need to update .legendables() to filter out the empty bins:

dc.override(pieactChart, 'legendables', function() {
    var legendables = this._legendables();
    return legendables.filter(function(l) {
        return l.data > 0;
    });
});

Fork of your fiddle: http://jsfiddle.net/gordonwoodhull/13t804u6/5/

Note: this only modifies the one (left) chart, you'll have to copy/paste it for each chart (or wrap it in a function) to apply it to other charts.

[I am very stubborn about not wanting such data filtering stuff inside the charts, so I'm not going to suggest this as a feature. Instead, legend should be a chart which takes its data from another chart, and there should be a way to transform that data.]

这篇关于dc.js饼图图例-如果结果为0,则隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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