简体   繁体   中英

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.

在此处输入图像描述

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

在此处输入图像描述

Thank you in advance.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM