Adjust datalabel to specific position (HIGHCHARTS)

2019-09-09 21:41发布

问题:

I want to set a datalabel for the VALUE to RIGHT of the bar, and the value of the SERIES (in my case "bar1, bar2, bar3") that are always at the LEFT of the bar. as it is in the picture.

this is my code

http://jsfiddle.net/pb1q9wzk/

plotOptions: {
 bar: {
   dataLabels: {
   padding: 0,
   allowOverlap: true,
   enabled: true,
   align: 'left',
   color: '#FFFFFF',
   inside: true,
   crop: false,
   overflow: "none",
   formatter: function() {            
    return this.series.name + " " + this.y;                       
  },
  style: {
    width:100
  }                       
.
.
.

回答1:

Just increase your align: right in plotOptions.

I hope this will solve your problem.

 plotOptions: {
            bar: {
                dataLabels: {
                padding:0,
                allowOverlap:true,
                    enabled: true,
                    align: 'right',
                    color: '#FFFFFF',
                    inside: true,
                    crop: false,
                    overflow:"none",
                        formatter: function() {

                    return this.series.name+ " "+ this.y;

                    console.log(this.series.name);
                },