d3.js - dc.js piechart legend: display only top 5 -
i generating piechart (doughnut chart precise) has around 50 items, top 5 of them accounts 95% of chart. when display legend info, overlapping chart, since there many legend items. wondering if there option limit legend display top 5 items.
https://github.com/dc-js/dc.js/blob/master/web/docs/api-latest.md#legend
i not see option limit legend display top 5 or top 10.
you can modify dc.js library can following in legend mixin:
dc.legend = function () { ... //start modification var _maxitems; _legend.maxitems = function(maxitems) { _maxitems = maxitems; return _legend; }; //end modification ... _legend.render = function () { _parent.svg().select('g.dc-legend').remove(); _g = _parent.svg().append('g') .attr('class', 'dc-legend') .attr('transform', 'translate(' + _x + ',' + _y + ')'); var legendables = _parent.legendables(); //start modification if (_maxitems) { legendables = legendables.slice(0, _maxitems); } //end modification ... }
Comments
Post a Comment