Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change echart axis label position

Tags:

svg

echarts

enter image description here

How can I place the axis label on the circled blank. I try many methods and couldn't achive it. Did anyone good at echarts tell me how to do?

Here is the offical example: echarts bar

like image 971
lai9fox Avatar asked Oct 22 '25 20:10

lai9fox


1 Answers

You can use series.label with a formatter to achieve this.

The series label is associated to a specific series and can be placed anywhere (position [0,0] being the top-left of the bar of that series). The formatter will allow you to display the series name in that label instead of the default value.

Of course, you have to put that label on only one series (otherwise it'll be displayed above each bar of the same 'category'). You'll also have to hide yAxis label. See full code here.

From your example :

yAxis: {
  type: 'category',
  data: ['Brazil', 'Indonesia', 'USA', 'India', 'China', 'World'],
  axisLabel: {
    show: false //hide yAxis label
  }
},
series: [
  {
    name: '2011',
    type: 'bar',
    data: [18203, 23489, 29034, 104970, 131744, 630230],
    label: {
      show: true,
      position: [5,-15], //put the label where you want
      formatter: function(params){
        return params.name //display series name
      }
    }
  },
]

enter image description here

like image 115
A mere dev Avatar answered Oct 25 '25 03:10

A mere dev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!