jQuery - 系列之外的HighCharts标签(条形图)

时间:2014-07-19 21:56:03

标签: jquery charts highcharts

$(function () {
$('#container').highcharts({
        chart: {
            type: 'bar',
            backgroundColor: null,
            width: 360
        },
        title: {
            text: null,
            style: {
                display: 'none'
            }
        },
        subtitle: {
            text: null,
            style: {
                display: 'none'
            }
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        xAxis: {
            categories: ['Cat 1', 'Cat 2', 'Cat 3', 'Cat 4', 'Cat 5', 'Cat 6', 'Cat 7', 'Cat 8', 'Cat 9', 'Cat 10'],
            title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            max: 10,
            gridLineWidth: 0,
            minorGridLineWidth: 0,
            title: {
                text: null
            },
            labels: {
                enabled: false
            }
        },
        tooltip: {
            enabled: false
        },  
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            },
            series: {
                dataLabels: {
                    crop: false,
                    enabled: true,
                    y: -2,
                    inside: false
                }
            }
        },
        series: [{
            showInLegend: false,
            name: '',
            color: '#CCC',
            data: [1, 2, 3, 9.4, 5, 6, 8, 9, 9, 9.5]

    }]
});
});

jsfiddle:http://jsfiddle.net/uNrW2/1/

我似乎无法将系列数据的标签始终显示在栏的右侧。 我已经浏览了所有API,但我似乎找不到阻止文本移动到栏中的选项。

有谁知道为什么会这样? 非常感谢你的时间!

1 个答案:

答案 0 :(得分:6)

您错过了名为plotOptions.series.dataLabels.overflowAPI)的API中的一个选项:

  

overflow:String

     

如何处理在绘图区域外流动的数据标签。默认值为justify,它将它们在绘图区域内对齐。对于柱和条,这意味着它将在条内移动。要在绘图区域外显示数据标签,请将crop设置为false,将overflow设置为"none"。默认为合理。

换句话说,你需要结合裁剪和溢出,像这样(updated JSFiddle):

plotOptions: {
    series: {
        dataLabels: {
            enabled: true,
            crop: false,
            overflow: 'none'
        }
    }
}