显示Highcharts Pie Slice Name onhover

时间:2015-09-21 19:08:16

标签: javascript highcharts hover slice pie-chart

我正在尝试为此饼图设置自定义工具提示文字。我想要在切片上显示每个切片的标签,以及在悬停事件中找到它们的方法,这样我就可以执行if / then / else来为每个切片显示一些自定义数据。

<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; max-width: 600px; margin: 0 auto"></div>

$(function () {
$('#container').highcharts({
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: 0,
        plotShadow: false
    },
    title: {
        text: '<span style="color: red;">&uarr;&uarr;&uarr;<br>Risk<br> ofInjury</span> ',
        align: 'center',
        verticalAlign: 'middle',
        useHTML:true,
        y: -20,
    },
    plotOptions: {
        pie: {
            dataLabels: {
                enabled: true,
                distance: -50,
                style: {
                    fontWeight: 'bold',
                    color: 'white',
                    textShadow: '0px 1px 2px black'
                }
            },
        }
    },
    tooltip: {
            useHTML: true,
            followPointer: false,
            formatter: function() { 
                return this.category + '<br><ul><li>List Item Test</li></ul>';
            }
    },
    series: [{
        type: 'pie',
        name: 'Factors',
        innerSize: '40%',
        data: [
            ['Data 1', 16],
            ['Data 2',16],
            ['Data 3',16],
            ['Data 4', 16],
            ['Data 5', 16],
            ['Data 6',16],
        ]
    }]
});

});

http://jsfiddle.net/5bqu7j4e/34/

1 个答案:

答案 0 :(得分:1)

在格式化程序功能中使用以下代码来获取标签

formatter: function() {
return '<b>'+ this.point.name +'</b>:<br><ul><li>List Item Test</li></ul>' ;
}

请参阅小提琴Here