aligning datalabel to top of column highcharts

2019-09-06 20:01发布

I'm trying to get my datalabel inside the column to the top if the column is going up or to the bottom if the column is going down right now with this code its aligned to the left in the middle.

plotOptions: {
        series: {
        stacking: 'normal',
            dataLabels: {
                align: 'top',
                enabled: true,
                formatter: function() {
                    return this.y.toFixed(2) +' %';
                }
            }
        }
    },

How would I do this? Also if the column displayed by highcharts isn't as wide as the text, how would I check for that and put the text over the column instead?

1条回答
不美不萌又怎样
2楼-- · 2019-09-06 20:34

You can "move" datalabels to bottom in negative columns, by translate function.

http://jsfiddle.net/wMLg6/33/

 var datalabel;

        $.each(chart.series[0].data,function(j,data){
            if(data.y < 0)
            {
                datalabel = data.dataLabel;
                datalabel.translate(datalabel.x,data.plotY-20);
            }
        });
查看更多
登录 后发表回答