Drashti Patel
Drashti Patel

Reputation: 75

Add label to column chart of Highchart

I am trying to make this chart using Highchart.js. Now I have to add labels in the format shown in the following picture. Can anyone help me out please. I am using ASP.net MVC and jquery for this.

enter image description here

The view is

  <div id="hourlyChart"></div>

And JS file is

Highcharts.chart('hourlyChart', {
    chart: {
        type: 'column'
    },
    credits: false,
    title: {
        text: ''
    },
    legend: { enabled: false },
    xAxis: {
        categories: label
    },
    yAxis: [{
        min: 0,
        title: {
            text: ''
        }
    }],
    legend: {
        shadow: false
    },
    tooltip: {
        shared: true
    },
    plotOptions: {
        column: {
            grouping: false,
            shadow: false,
            borderWidth: 0
        }
    },
    series: [{
        name: 'Target',
        color: 'rgba(189, 195, 199, 1)',
        data: target,
        showInLegend: false,
    }, {
        name: 'Achieved',
        color: 'rgb(242, 38, 19)',
        data: achieved,
        pointPadding: 0.2,
        showInLegend: false          
    }
    ]
});

From this I am getting this much result

enter image description here

Thank you in advance.

Upvotes: 0

Views: 1008

Answers (1)

ppotaczek
ppotaczek

Reputation: 39079

Use data-labels and position them by y property. Example:

    plotOptions: {
        column: {
            ...,
            dataLabels: {
                verticalAlign: 'bottom',
                allowOverlap: true,
                enabled: true,
                inside: true
            },
        }
    },
    series: [{
        dataLabels: {
            color: 'rgba(189, 195, 199, 1)',
            y: -310
        },
        ...
    }, {
        dataLabels: {
            color: 'rgb(242, 38, 19)',
            y: -330
        },
        ...
    }]

Live demo: http://jsfiddle.net/BlackLabel/hvxbpqj5/

API Reference: https://api.highcharts.com/highcharts/series.column.dataLabels

Upvotes: 1

Related Questions