Andrei Ivanov
Andrei Ivanov

Reputation: 311

Changing the way the data is shown in Highcharts

I have a little problem, I have a pie chart generated by highcharts - and it represents the data in percentage. So for example if I have two values 2 and 3, it will show on the chart drawn 40% and 60%. Instead of showing the data in pecentage I actually want to display those numbers on the chart drawn: 2 and 3. Anyone knows what would I have to change to display numbers and not percentage? Thanks!

chart: 
        {
            renderTo: 'sunshine',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: 
        {
            text: 'Browser market shares at a specific website, 2010'
        },

        tooltip: 
        {
            pointFormat: '{series.name}: <b>{point.percentage}%</b>',
            percentageDecimals: 1
        },
        plotOptions: 
        {
            pie: 
            {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: 
                {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() 
                    {
                        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                    }
                }
            }
        },
        series: [
        {
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Jan',   2],
                ['Feb',       3],
            ]
        }]
    });

Upvotes: 0

Views: 86

Answers (1)

Eric H.
Eric H.

Reputation: 7014

Use the label formatter for the pie attribute. You can access the exact data point with the this.y value:

 pie: 
        {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: 
            {
                enabled: true,
                color: '#000000',
                connectorColor: '#000000',
                formatter: function() 
                { 
                    return '<b>'+ this.point.name +'</b>: '+ this.y;
                }
            }
        }

Upvotes: 2

Related Questions