HighChart Stacked Column标签问题

时间:2015-02-12 17:01:54

标签: javascript jquery highcharts label jsfiddle

我有一个图表,其值不均匀,即:第一个值是1315,第二个值是1,依此类推,当显示图表时,标签重叠。我已经在多个论坛中搜索过,但没有人遇到完全相同的问题。这是查看问题的小提琴:http://jsfiddle.net/6LutjLc3/

$(function () {
$('#container').highcharts({
    chart: {
        type: 'column'
    },
    title: {
        text: 'Stacked column chart'
    },
    xAxis: {
        categories: ['Issue']
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Total fruit consumption'
        },
        stackLabels: {
            enabled: true,
            style: {
                fontWeight: 'bold',
                color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
            }
        }
    },
    legend: {
        align: 'right',
        x: -30,
        verticalAlign: 'top',
        y: 25,
        floating: true,
        backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
        borderColor: '#CCC',
        borderWidth: 1,
        shadow: false
    },
    tooltip: {
        formatter: function () {
            return '<b>' + this.x + '</b><br/>' +
                this.series.name + ': ' + this.y + '<br/>' +
                'Total: ' + this.point.stackTotal;
        }
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            dataLabels: {
                enabled: true,
                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                style: {
                    textShadow: '0 0 3px black'
                }
            }
        }
    },
    series: [{
        name: 'John',
        data: [1235]
    }, {
        name: 'Toto',
        data: [2]
    }, {
        name: 'Matt',
        data: [1]
    }, {
        name: 'Jane',
        data: [72]
    }, {
        name: 'Joe',
        data: [3]
    }]
});

});

我需要编码的是将值1放在标签所适合的框中,就像在高级图中的任何其他示例一样。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

如果您的客户要求使用此样式的图表,您可以通过修改dataLabel设置获得更好看的结果。将overflow设置为false并添加一个仅返回值的格式化程序函数,如果它允许至少7%(或任何最适合您的百分比)的当前总数将有所帮助。请参阅以下内容:

&#13;
&#13;
dataLabels: {
    enabled: true,
    overflow: false,
    color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
    style: {
        textShadow: '0 0 3px black'
    },
    formatter: function () {        
        if (this.percentage >= 7) return this.y;
    }
}
&#13;
&#13;
&#13;

在这里小提琴:http://jsfiddle.net/6LutjLc3/4/

相关问题