Chris
Chris

Reputation: 282

Show Highcharts Pie Slice Name onhover

I'm trying to set a custom tooltip text for this pie chart. I want the labels of each slice showing on the slice, as well as having a way of getting to them in the hover event so I can do an if/then/else to show some custom data for each slice.

<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/

Upvotes: 0

Views: 1362

Answers (1)

Nishith Kant Chaturvedi
Nishith Kant Chaturvedi

Reputation: 4769

Use follow code in formatter functin to get labels

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

See fiddle Here

Upvotes: 1

Related Questions