Highcharts - 饼图内外的标签

sup*_*rue 11 highcharts

我知道可以通过更改plotOptions.pie.dataLabels.distance将饼图标签放在饼图内部或外部.我想弄清楚是否可以逐点改变它:

如果切片小于15%,则在切片内放置标签

否则将标签放在切片之外

在Highcharts中这可能吗?以下是我的尝试之一,但不起作用; 简单的jsfiddle在这里:http://jsfiddle.net/supertrue/q6bQP/

plotOptions: {
    pie: {
        dataLabels: {
            distance: -30,
            color: 'white',
            formatter: function() {
                if (this.y < 15 ) {
                    this.point.dataLabels.color = 'red';
                    this.point.dataLabels.distance = 20;
                    return this.point.name;
                } else {
                    return this.point.name;
                }

        }
  },
Run Code Online (Sandbox Code Playgroud)

rol*_*res 2

这篇文章可以帮助您完成您的工作:

是否可以根据值定位 Highcharts 数据标签?

$.each(chart.series[0].data, function(i, point) {
    // using the value or calculating the percent        
    if(point.percentage < 30) {
        point.dataLabel.attr({y:20});
    }
});
Run Code Online (Sandbox Code Playgroud)