echarts gauge控制宽度

echarts yekong 1069℃

vue数据大屏开发,当echarts图表变小的时候 因为宽度太大,导致图表看起来变形,需要调小一些,搜索了一番才找到解决办法。
echarts gauge控制宽度

关键代码

通过axisLine lineStyle width控制

axisLine: {
  show: true,
  lineStyle: {
    width: 10,
  }
},

完整代码

<template>
  <div class="echarts1" ref="echarts1">

  </div>
</template>

<script>

import _ from 'lodash'

export default {
  name: 'echarts1',
  components: {},
  data() {
    return {}
  },
  props: {
    color: {
      type: String,
      default() {
        return ''
      }
    },
    color2: {
      type: String,
      default() {
        return ''
      }
    },
    number: {
      type: String,
      default() {
        return ''
      }
    }
  },
  mounted() {
    var that = this
    _.delay(function (text) {
      that.drawLine()
    }, 1000, 'later')
  },
  methods: {
    drawLine() {
      var that = this
      window.addEventListener('resize', this.drawLine)
      let myChart = this.$echarts.init(this.$refs.echarts1)
      var dataArr = [{
        value: this.number,
        name: ''
      }]
      var color = new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
        offset: 0,
        color: that.color2
      },
        {
          offset: 1,
          color: that.color
        }
      ])
      var rich = {
        bule: {
          fontSize: 14,
          fontFamily: 'DigitalDismay',
          color: 'rgba(44, 192, 204, 1.00)',
          fontWeight: '700',
        },
      }
      var colorSet = [
        [this.number / 100, color],
        [1, '#0E394D']
      ]
      var option = {
        tooltip: {
          formatter: '{a} <br/>{b} : {c}%'
        },
        progress: {
          width: 10
        },
        series: [
          {
            type: 'gauge',
            radius: '100%',
            startAngle: '225',
            endAngle: '-45',
            pointer: {
              show: false
            },
            data: dataArr,

            detail: {
              formatter: function (value) {
                var num = Math.round(value)
                return '{bule|' + num + '%}'
              },
              rich: rich,
              offsetCenter: ['0%', '0%'],
            },
            title: {
              show: true,
              color: '#fff',
              fontStyle: 'normal',
              fontWeight: 'normal',
              fontFamily: '微软雅黑',
            },
            axisLine: {
              show: true,
              lineStyle: {
                width: 10,
                color: colorSet,
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                opacity: 1
              }
            },
            axisTick: {
              show: false
            },
            splitLine: {
              show: false,
              lineStyle: {
                color: 'rgba(242, 100, 57, 1)',
                width: 2,
                type: 'solid',
              },
            },
            axisLabel: {
              show: false
            },
          },
        ]
      }
      myChart.clear()
      myChart.resize()
      myChart.setOption(option)
    },
  }
}
</script>

<style lang="scss" scoped>
.echarts1 {
  position: relative;
  width: 100%;
  height: calc(100% - 10px);
}
</style>

喜欢 (4)