ECharts 注意点

yAxis轴的数据和 series中的 yAxisIndex: 坐标值相对性

vue 

https://www.npmjs.com/package/vue-echarts

解决销毁实例和内存泄露

beforeDestroy () {
this.$refs['chart'].clear()
this.$refs['chart'].dispose()
}
<template>
  <chart ref="chart"  :options="options" v-if="options" :auto-resize="autoResize" :watchShallow="watchShallow"></chart>
</template>

<script>
// 环比波动图表
export default {
  name: 'WaveRatio',
  props: ['mount', 'count', 'flag'], // 当flag为true,Y轴不加%号
  data () {
    return {
      autoResize: true,
      watchShallow: true
    }
  },
  computed: {
    options () {
      let labelTop = {
        normal: {
          position: 'top',
          rotate: 90,
          verticalAlign: 'middle',
          align: 'left',
          color: '#666'
        }
      }
      let labelBottom = {
        normal: {
          position: 'bottom',
          rotate: 90,
          verticalAlign: 'middle',
          align: 'right',
          color: '#666'
        }
      }
      let dataList = []
      let current = 0 // 记录数据
      for (let i = 0; i < this.count.length; i++) {
        this.count[i] * 1 >= 0 ? dataList.push({value: this.count[i], label: labelBottom}) : dataList.push({value: this.count[i], label: labelTop})
        if (this.count[i] * 1 >= 0) {
          current++
        } else {
          current--
        }
      }
      let count = this.count
      let noPercent = this.flag
      let dataZoomShow = this.mount.length > 30
      let dataZoom = null
      if (dataZoomShow) {
        dataZoom = [
          {
            type: 'slider',
            show: true,
            xAxisIndex: 0,
            filterMode: 'empty',
            width: '85%',
            height: 10,
            handleSize: 8,
            showDataShadow: false,
            left: '5%',
            bottom: '1%',
            start: 0,
            end: 45,
            fillerColor: 'rgba(0,0,0,.3)',
            showDetail: false
          }
        ]
      }
      let bottomValue = current === count.length
      let topValue = -current === count.length
      return {
        dataZoom: dataZoom,
        tooltip: {
          trigger: 'axis',
          backgroundColor: 'rgba(0,22,41,.7)',
          axisPointer: {
            type: 'line'
          },
          padding: [15, 20],
          formatter: function (params) {
            if (noPercent) {
              return params[0].name + '<span style="display:block;line-height:30px;">' + params[0].marker + params[0].seriesName + ': ' + params[0].value + '</span>'
            } else {
              return params[0].name + '<span style="display:block;line-height:30px;">' + params[0].marker + params[0].seriesName + ': ' + params[0].value + '% </span>'
            }
          }
        },
        grid: {
          bottom: bottomValue ? 90 : 40,
          left: 12,
          top: topValue ? 90 : 40,
          right: 0,
          containLabel: true
        },
        yAxis: {
          type: 'value',
          position: 'top',
          splitLine: {
            lineStyle: {
              color: '#eee'
            }
          },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            formatter: noPercent ? '{value}' : '{value}%',
            color: '#666'
          }
        },
        xAxis: {
          type: 'category',
          axisLine: { show: false },
          axisLabel: { show: false },
          axisTick: { show: false },
          splitLine: { show: false },
          data: this.mount
        },
        series: [
          {
            name: noPercent ? '指数' : '环比',
            type: 'bar',
            barMaxWidth: 10,
            itemStyle: {
              color: '#79b6fd'
            },
            label: {
              normal: {
                show: true,
                formatter: function (params) {
                  if (Math.abs(current) === count.length) {
                    return params.name.length > 5 ? params.name.substring(0, 5) + '...' : params.name
                  } else {
                    return params.name
                  }
                }
              }
            },
            data: dataList
          }
        ]
      }
    }
  },
  beforeDestroy () {
    this.$refs['chart'].clear()
    this.$refs['chart'].dispose()
  }
}
</script>

<style scoped>
</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值