Maki
Maki

Reputation: 199

Add additional data to Pie Tooltip on Highcharts

I'm trying to add additional data to my pie chart using highcharts. Try to explain: I have a Pie Chart of Browsers:

I would like to add more info to display in the tooltip: For example:

The values I putted are invented, I would like to understand how to customize the tooltip and add some more data to the series.

My JsFiddle code

This is my JS code for the Pie:

<script>
    $(function () {
        $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false,
                type:'pie'
            },

            title: {
                text: 'Browsers'
            },

            subtitle: {
                text:false,
            },

            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },

            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                        style: {
                            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                        }
                    }
                }
            },

            series: [{
                name: "Total",
                colorByPoint: true,
                data: [{
                    name: "Firefox",
                    y: 10,
                }, {
                    name: "Chrome",
                    y: 12,
                }, {
                    name: "Explorer",
                    y: 65,
                }, {
                    name: "Opera",
                    y: 13,
                }]
            }],

        });
    });
</script>

This is an image to understand what I would like to do: enter image description here

Thanks

Upvotes: 6

Views: 11370

Answers (3)

Dhiren Biren
Dhiren Biren

Reputation: 530

can try like this

tooltip: { headerFormat: '{series.name}: {point.y}',

      pointFormat: '{series.name}: <b><br/>Totalamount: {point.amount}'

    },

Upvotes: 0

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

You can also use tooltip.formatter and extract values from this.point.options.custom (where custom if name of field like in examples above)

http://api.highcharts.com/highcharts#tooltip.formatter

Upvotes: 1

Nishith Kant Chaturvedi
Nishith Kant Chaturvedi

Reputation: 4769

you can put custom data in series and then use in tooltip

data: [{
            name: "Firefox",
            y: 10,
    custom:"5% "
        }, {
            name: "Chrome",
            y: 12,
     custom:"10% "
        }, {
            name: "Explorer",
            y: 65,
     custom:"15%"
        }, {
            name: "Opera",
            y: 13,
     custom:"25% "
        }]

Use in tooltip

  tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b> <br>of which woman users {point.custom}'
    }

See updated fiddle here

Upvotes: 9

Related Questions