如何在数据栏的基础上定位数据标签

Ste*_*veJ 4 highcharts

我有一个(水平)条形图,我想在系列栏的基础(或最左边部分)添加dataLabel.

与此类似:http: //flowingdata.com/2009/05/22/poll-results-what-data-related-area-are-you-most-interested-in/

有没有办法使用formatter函数来设置这个值?

plotOptions: {
    bar: {         
        dataLabels: {
            formatter: function() {
                this.series.options.dataLabels.x =  ?????????????
                return this.y;
            },
Run Code Online (Sandbox Code Playgroud)

eol*_*son 12

formatter函数的任务是格式化标签文本.它为您提供了一种修改图表内部状态的方法,但这实际上只是一个黑客,因此可能会或可能不会.

将标签放置在底座的一种方法是使用堆栈标签而不是数据标签(数据标签将放置在栏的顶部,向左或向右对齐).要在基础上配置堆栈标签,请执行以下操作:

yAxis: {                         // The y axis is horizontal 'bar' layout
    stackLabels: {
        style: {
            color: 'white'       // Make the labels white
        },
        enabled: true,           // Enable stack labels
        verticalAlign: 'middle', // Position them vertically in the middle
        align: 'left'            // Align them to the left edge of the bar
    }
}
Run Code Online (Sandbox Code Playgroud)

您还需要将堆叠设置为'normal':

关于jsfiddle的示例:

在此输入图像描述

更新:堆栈总计的标签将显示特定类别(堆栈)的所有系列的总和,因此仅​​在图表中具有单个系列的情况下,堆栈标签和数据标签显示相同的值.