aligning datalabel to top of column highcharts

社会主义新天地 提交于 2019-12-13 20:46:52

问题


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:


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


来源:https://stackoverflow.com/questions/15116858/aligning-datalabel-to-top-of-column-highcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!