Luís de Sousa
Luís de Sousa

Reputation: 6842

Highcharts: overlay label on a graph

I'd like to overlay a custom layer over a chart (e.g. a comment, author). Reading the API there seems to be already an object for the purpose:

A HTML label that can be positioined anywhere in the chart area.

I tried using this on one of the example charts but it has no effect (see below), although the interpreter isn't issuing any error. Am I doing something wrong or should a lable of this kind be created some other way?

Thank you.

    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'pie-container',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2010'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage}%',
            percentageDecimals: 1
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#FFFFFF',
                    connectorColor: '#FFFFFF',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            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]
            ]
        }],
        labels: [
            {html: "<b>This is a label!</b>", 
            style: {
                left: '100px', 
                top: '100px',
                width: '50px'}}],
      });
   });
});

Upvotes: 2

Views: 3662

Answers (1)

Ricardo Lohmann
Ricardo Lohmann

Reputation: 26320

labels should be an object.
Then you have to add each label as an element of items.

labels: {
    items: [{
        html: "<b>This is a label!</b>",
        style: {
            left: '100px',
            top: '100px',
            width: '50px'
        }
    }]
}

Demo

Upvotes: 4

Related Questions