6

Using Echarts3.0 in Vuejs2.0 component, I am trying to assign percent on y-axis in a stacked bar chart. I tried boundaryGap, splitnumber, etc, but none of them worked. But i cannot achieve it, Anyone has idea how can i get % on y-axis?

export default {
  data: () => ({
    loading: true,
    bar: {              
    xAxis:  {
            type: 'category',
            data: ['Location1','Location2']
        },
    yAxis: {
            type: 'value',
           splitNumber: 10,
           boundaryGap: ['0', '100%'],
           min:0,
           max:100,
            scale:true,
            splitArea : {show : true},
            label: {
                 formatter: function(){
                 return 100 * value /$(this.axis.tickPositions).last()[0]                              
                 + '%';
                       }
                   }
            },
     series: [
            {
                name: 'Location1',
                type: 'bar',
                stack: 'one',
                label: {
                    normal: {
                        show: true,
                        position: 'insideRight'
                    }
                },
                data: [1100, 2050]
            },
            {
                name: 'Location2',
                type: 'bar',
                stack: 'one',
                label: {
                    normal: {
                        show: true,
                        position: 'insideRight'
                    }
                },
                data: [291064, 34789]
            }
        ]
        }

})

WonderHeart
  • 678
  • 10
  • 28

2 Answers2

11

Set yAxis in below format

yAxis: [{
  type: "value",
  name: "%",
  axisLabel: {
    formatter: "{value} %"
  }
}]
Shahin Belim
  • 155
  • 1
  • 9
1

you have to calculate maxValue first, then...

  yAxis: [
    {
      type: 'value',
      axisLabel: {
        formatter: (value) => {
          return Math.floor(100 * value / maxValue) + '%';
        }
      }
    }
  ],
Tim2.0
  • 109
  • 1
  • 2