【问题标题】:Bar chart label alignment for all the zero values所有零值的条形图标签对齐
【发布时间】:2018-01-25 11:37:49
【问题描述】:

我正在为条形图使用高图表库。除了一件事,一切都很好。 当 bar 中的所有值都为“零”时,对齐方式已更改为右侧。我想让它左对齐。对于任何非零值,它都按预期工作。

这里是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]
    }]
});

任何帮助将不胜感激。

【问题讨论】:

标签: javascript html highcharts bar-chart


【解决方案1】:

如果所有的值都是0,那么max是无法计算出来的,所以Highcharts会在中间渲染值。您可以通过设置yAxis.maxyAxis.softMax 来强制将标签呈现在左侧,演示:https://jsfiddle.net/BlackLabel/mvp1ebsj/1/

【讨论】:

    猜你喜欢
    • 2014-03-10
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多