数据标签有时会显示在栏内

时间:2017-09-12 10:45:46

标签: highcharts

有时数据标签会显示在栏内。 例如,在“亚洲”栏的给定jsfiddle中,数据标签显示在栏内部。 有没有办法在栏外显示数据标签。

http://jsfiddle.net/n3me6r8k/

Highcharts.chart('container', {
    chart: {
        type: 'bar'
    },
    title: {
        text: 'Historic World Population by Region'
    },
    subtitle: {
        text: 'Source: <a href="https://en.wikipedia.org/wiki/World_population">Wikipedia.org</a>'
    },
    xAxis: {
        categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
        title: {
            text: null
        }
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Population (millions)',
            align: 'high'
        },
        labels: {
            overflow: 'justify'
        }
    },
    tooltip: {
        valueSuffix: ' millions'
    },
    plotOptions: {
        bar: {
            dataLabels: {
                enabled: true
            }
        }
    },
    credits: {
        enabled: false
    },
    series: [{
        name: 'Year 2012',
        data: [1052, 954, 4250, 740, 38]
    }]
});

1 个答案:

答案 0 :(得分:1)

是的,可以通过在dataLabels配置中设置两个参数来完成,即:

dataLabels: {
        enabled: true,
        crop: false,
        overflow: "none"
}

通常情况下,Highcharts会在栏中移动标签,因为它可以通过div框架进行裁剪。上面的配置允许您设置不会裁剪标签,即使它们超出图表容器。

JSFiddle:http://jsfiddle.net/daniel_s/8m1b4arv/

API参考:http://api.highcharts.com/highcharts/series%3Cbar%3E.dataLabels.crop

相关问题