简体   繁体   English

如何使highcharts pie数据标签始终位于每个切片的中心?

[英]how to make highcharts pie datalabels always in center of each slice?

I really want to know how to make datalabels always in center of each slice in pie chart. 我真的想知道如何在饼图中使数据标签始终位于每个切片的中心。

The normal state look like this(you can also see this example here ) 正常状态看起来像这样(你也可以在这里看到这个例子)

在此输入图像描述

$('#container').highcharts({
    chart: {
        type: 'pie'
    },

    plotOptions: {
        pie: {
            center:  ["50%", "50%"],
            dataLabels: {
                distance: -50
            }
        },
        series:{
            events:{
                load:function(){
                    console.log(this.chartWidth, this.chartHeight);   
                }
            }
        }
    },

    series: [{
        data: [
            ['Firefox',   44.2],
            ['IE7',       26.6],
            ['IE6',       20],
            ['Chrome',    3.1],
            ['Other',    5.4]
        ]
    }]
});

But, when I decrease the width or height of this chart, datalabels combined, which look like the image below. 但是,当我减小此图表的宽度或高度时,数据标签会合并,如下图所示。 I think it is the problem of distance property. 我认为这是distance财产的问题。 I've tried to change distance dynamically but failed. 我试图动态改变距离但失败了。

在此输入图像描述

As a result, what I want to do is to locate datalabels always in center of the each slice even decreasing/increasing chart size. 因此,我想要做的是将数据标签定位在每个切片的中心,甚至降低/增加图表大小。

This is a tough one. 这是困难的一个。 From my experiences, there's not (currently) a way to explicitly center the labels directly in the middle of each pie slice. 根据我的经验,目前还没有一种方法可以直接在每个饼图的中间明确地居中标签。 I've tried positioning the labels as you did in your example with the same (unsatisfactory) results, especially in smaller browser windows. 我已经尝试像在您的示例中那样使用相同(不令人满意的)结果来定位标签,尤其是在较小的浏览器窗口中。

I'd recommend either using a legend to show the categories/types in your pie or consider using a stacked bar chart instead (see http://www.highcharts.com/demo/bar-stacked ). 我建议您使用图例来显示饼图中的类别/类型,或者考虑使用堆叠条形图(请参阅http://www.highcharts.com/demo/bar-stacked )。

I hope this is helpful! 我希望这是有帮助的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM