如何在饼图中对齐数据标签

时间:2014-03-11 10:21:40

标签: php jquery highcharts pie-chart

我在highcharts中有一点问题。我创建了具有数据标签的饼图。我的问题是,当数据标签的长度很大,然后它移出区域,其中一部分消失。 lat看看我的代码

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

Jquety

$(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',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                },
                size:[40],
                    startAngle: -90,
                    endAngle: 90,
                    center: ['50%', '100%']
            }
        },
        series: [{

            type: 'pie',
                name: 'Amount',
                innerSize: '100%',
                colors: ['#50B432', '#ED561B','#24CBE5'],
                dataLabels: {
                    enabled: true,
                    rotation: 0,
                    color: '#666666',
                    align: 'top',
                    x: -10,
                    y: -10,
                    style: {
                        fontSize: '9px',
                        fontFamily: 'Verdana, sans-serif',
                        textShadow: '0 0 0px black'
                    }
                },
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]
    });
});

这里是Fiddle

我希望它像Demo fiddle。在小提琴中,每个数据标签总是在图表区域中移动 没有消失。

注意我已经解决了条形图和其他图表中的问题。

提前致谢

1 个答案:

答案 0 :(得分:1)

你可以

  • 缩小图表大小
  • 使用distance 参数。
  • 设置useHTML并通过css
  • 进行修改