echart柱狀圖柱子與label顏色一致


 

 

echart1(){
      this.box1Echart = this.$echarts.init(this.$refs.box1Dom)
      let colors = ['#f00', '#ff0', '#00f', '#0f0']
      var option = {
        titile: {
          show: false,
        },
        tooltip:{
          trigger: 'item',
          formatter: '{b}'
        },
        xAxis : [
            {
                type : 'category',
                show: false,
                data : ['最多','平均','最少'],
                axisLabel: {
                  interval :0
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                name:'數量',
                 min: 0,
                 max: 30,
                 interval: 6,
                 axisLabel: {
                     formatter: '{value} 包'
                 }
            }
        ],
        series : [
            {
                name: '數量',
                type: 'bar',
                itemStyle: {
                    normal: {
                        color: function(params) {
                            return colors[params.dataIndex]
                        },
                        label: {
                            show: true,
                            position: 'top',
                            formatter: '{b}\n{c}'
                        }
                    }
                },
                barWidth:30,
                data: [28,15,9,4,7,8,23,11,17]
            }
        ]
      }
      
      this.box1Echart.setOption(option);

    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM