代码小tip echarts折线点击

<template>
    <div :style="{width:`${width}px`,height:`${height}px`}" :id="datachart"></div>
</template>

<script>
import echarts from 'echarts';

export default {
  name: 'datachart',
  data() {
    return {
    };
  },
  props: {
    datachart: String,
    width: Number,
    height: Number,
    chartInfo: Object,
    isCompare: Boolean
  },
  computed: {
    opt() {
    /*  eslint-disable */
      let that = this;
      let option = {
        tooltip: {
            trigger: 'axis',
            // axisPointer : { // 坐标轴指示器,坐标轴触发有效
            //     type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
            // },
            position: function (pt) {
                return [pt[0], '10%'];
            }
        },
        // title: {
        //     left: 'center',
        //     text: '',
        // },
        legend: {
            data:[],
            y: 'bottom'
        },
        xAxis: {
          type:'category',
          boundaryGap: false,
          data: [],
        },
        yAxis: {
            type: 'value',
            boundaryGap: [0, 0.2]
        },
        series: [
            {
                name:'',
                type:'line',
                clickable : true,      
                smooth:true,
                // symbol: 'none',
                sampling: 'average',
                itemStyle: {
                    color: '#409EFF'
                },
                data: []
            },
            {
              name:'',
              type:'line',
              clickable : true,      
              smooth:true,
              // symbol: 'none',
              sampling: 'average',
              itemStyle: {
                  color: 'green'
              },
              data: []
          },
        ]
    };
    return option;
 /* eslint-enable */
    }
  },
  methods: {
    drawcharts(index) {
      const visiteVolume =             
      echarts.init(document.getElementById(`dataChart${index}`));
      this.opt.xAxis.data = this.chartInfo.chartInfoX;
      this.opt.series[0].data = this.chartInfo.chartInfoY;
      this.opt.series[0].name = this.chartInfo.chartInfoL[0];
      if (this.isCompare) {
        this.opt.series[1].data = this.chartInfo.constractChartInfoY;
        this.opt.series[1].name = this.chartInfo.chartInfoL[1];
      } else {
        this.opt.series[1].data = [];
        this.opt.series[1].name = '';
      }
      this.opt.legend.data = this.chartInfo.chartInfoL;
      visiteVolume.setOption(this.opt, true);
      visiteVolume.off('click');
      visiteVolume.on('click', params => {
        this.$emit('callBackName', params.name);
      });
      window.addEventListener('resize', () => {
        visiteVolume.resize();
      });
    }
  }
};
</script>

注意点:1.symbol: 不能为 'none',2.echarts如果是多个实例需要通过id new多次

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值