调整datalabel列highcharts顶部datalabel、highcharts

2023-09-11 08:01:15 作者:我要化学渣为学霸 *

我试图让我的datalabel柱内顶端如果列正在上升或底部,如果列正在下降为c的这个$ C $左对齐,中间现在。

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) +' %';
                }
            }
        }
    },

我将如何做到这一点?此外,如果通过highcharts显示的列不一样宽的文字,我怎么会检查这一点,把文字放在列呢?

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?

推荐答案

您可以在移动datalabels到底负列,通过翻译功能。

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);
            }
        });