Highcharts Pie Chart.How to set labels in two lines

偶尔善良 提交于 2020-01-01 08:29:19

问题


I'm creating a pie chart in highcharts.

Does anybody know how to set data labels in two lines?

I'm finding this problem when the data labels are too long.

http://jsfiddle.net/larrytron/fSjnD/

    $(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2010'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    maxStaggerLines:1,                    
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'                   

                },
            }
        },

        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox jandler glander gramenauer gramen',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]
    });
});

回答1:


You can simply set width for dataLabels, see: http://jsfiddle.net/Fusher/fSjnD/1/

style: {
    width: '100px'
}



回答2:


You can simply insert
in the data labels:

 data: [
      ['Firefox jandler glander <br><b>gramenauer gramen</b>',   45.0],

Note, for some reason, the second line loses the bold formatting unless you addit back in using tags.

http://jsfiddle.net/ZMLSW/



来源:https://stackoverflow.com/questions/18329478/highcharts-pie-chart-how-to-set-labels-in-two-lines

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