简体   繁体   中英

highcharts / highstock column doesn't show all datalabels

I have a highstock column chart which doesn't show all of the values - I've tried to simplify it as much as possible for this example. I'm using highstock because I need a horizontal scroll bar on the column.

 $('#container').highcharts({
    tooltip: {
        formatter: function () {
            if (this.y === '' && this.y !== 0) {
                return this.series.name + '<br/>' + this.x + ': NO DATA';
            }

            return this.series.name + '<br/>' + this.x + ': ' + this.y;
        }
    },      
    chart: {
        type: 'column'
    },
    title: {
        text: null
    },
    subtitle: {
        text: null
    },
    xAxis: {
        categories: labels,
        title: {
            text: null
        },
        labels: {
            style: {
                color: '#000',
            }
        },
        lineWidth: 2,
        lineColor: '#000',
        tickWidth: 2,
        tickLength: 12,
        tickColor: '#000',
        startOnTick: true,
    },
    yAxis: {
        title: {
            text: 'test',
            align: 'middle',
            style: {
                color: '#000',
            }
        },
        labels:{enabled: false},
        style: {
            color: '#000',
        },
        gridLineColor: 'transparent',
        lineWidth: 2,
        lineColor: '#000',
    },
    plotOptions: {
        series: {
            dataLabels: {
                enabled: true,
            }
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'top',
        x: 0,
        y: 100,
        floating: false,
        borderWidth: 0,
        backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
        shadow: true
    },      
    credits: {
        enabled: false
    },
    series: series
});

Here is a fiddle: https://jsfiddle.net/ypw4gx1h/

Some data labels are not showing because they would be overlapping nearby data labels. With a column chart dataLabels.allowOverlap is set to false by default. You could change this to true in your code like this ( JSFiddle example ):

plotOptions: {
    series: {
        dataLabels: {
            enabled: true,
            allowOverlap: true
        }
    }
}

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