简体   繁体   English

所有零值的条形图标签对齐

[英]Bar chart label alignment for all the zero values

I am using high-chart library for bar chart. 我正在使用条形图的高图表库。 Everything is working fine except one thing. 除了一件事,一切都工作正常。 When all the values in bar are 'ZERO', the alignment has changed into right side. 当条中的所有值均为“ 0”时,对齐方式已更改为右侧。 I want to make it left align. 我想使其左对齐。 For any non zero values it's working as expected. 对于任何非零值,它都按预期工作。

Here is the Fiddle 这是小提琴

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',
            align:'left'
        }
    },
    tooltip: {
        valueSuffix: ' millions'
    },
    plotOptions: {
        bar: {
            dataLabels: {
                enabled: true
            }
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'top',
        x: -40,
        y: 80,
        floating: true,
        borderWidth: 1,
        backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
        shadow: true
    },
    credits: {
        enabled: false
    },
    series: [{
        name: 'Year 1800',
        data: [0, 0, 0, 0, 0]
    }]
});

Any help would be appreciated. 任何帮助,将不胜感激。

If all values are 0 , then max can not be calculated, so Highcharts will render values in the middle. 如果所有值均为0 ,则无法计算max ,因此Highcharts将在中间渲染值。 You can force labels to be rendered on the left by setting yAxis.max or yAxis.softMax , demo: https://jsfiddle.net/BlackLabel/mvp1ebsj/1/ 您可以通过设置yAxis.maxyAxis.softMax演示在左侧显示标签: https : yAxis.softMax

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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