redraw pie chart in highchart

我只是一个虾纸丫 提交于 2019-12-06 14:40:58

问题


suppose I have 4 slices having 20%, 30%, 30% and 20%. If I make 4th slice(20%) inactive, the other slices should adjust themselves and occupy 100 %. how to do this in highcharts? Thank you.


回答1:


I don't think it's possible to alter this behavior. Instead you need to remove the point all together for the other slices to add up to 100. Here is an example that shows the difference between legend-toggle and point remove: jsfiddle




回答2:


I think this should be the standard behavior :)

opts.plotOptions.pie.point.events.legendItemClick = function() {
    if (this.visible) {
        this['y_old'] = this.y;
        this.update(0);
    }
    else {
        this.update(this.y_old);
    }
};

now when you click on a legend item the pie chart slice will disappear

If you want to show the percentage (100% without the now missing slice) you have to define your tooltip (or legend) as:

opts.tooltip.formatter = function() {
    var s = '<b>' + this.point.name + '</b>: ' + this.percentage.toFixed(2) + '%';

    return s;
};



回答3:


This feature is now available out of the box as plotOptions.pie.ignoreHiddenPoint

 series: [{
    ignoreHiddenPoint: true,
    type: 'pie',
    ...
  }]

Auto Redraw/Recalculate Pie on Legend | Highchart & Highstock @ jsFiddle



来源:https://stackoverflow.com/questions/10514025/redraw-pie-chart-in-highchart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!