echarts——图例+自定义tooltip——tooltip前面的小点根据柱状图颜色来自动渲染

在这里插入图片描述

//柱状图+折线图
    GradientColumn(id, xaxisData, yaxisData, flash = false) {
      var myChart = echarts.init(document.getElementById(id));
      myChart.clear();
      let option = {
        legend: {
          x2: '20px',
          y: '0',
          itemWidth: 18,
          itemHeight: 10,
          icon: 'rect',
          textStyle: {
            //图例文字的样式
            color: '#000',
            fontSize: 14,
          },
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
          backgroundColor: 'rgba(255,255,255,0.8)',
          extraCssText: 'box-shadow: 2px 2px 4px 0px rgba(0,0,0,0.3);',
          textStyle: {
            fontSize: 14,
            color: '#000',
            align: 'left',
          },
          formatter: (params) => {
            var html = params[0].axisValue + '<br>';
            params.forEach((item, index) => {
              html +=
                item.marker +
                '' +
                item.seriesName +
                ':' +
                item.value +
                (item.seriesName && item.seriesName.indexOf('利用率') > -1
                  ? '%'
                  : '') +
                '<br>';
            });
            return html;
          },
        },
        color: ['#FFB74A', '#F17B2C', '#fc8452', '#9a60b4', '#ea7ccc'],
        grid: {
          x: 30,
          y: 50,
          x2: 40,
          y2: 30,
          containLabel: true,
        },
        xAxis: [
          {
            type: 'category',
            axisLabel: {
              interval: 0,
              color: '#000',
              fontSize: 14,
            },
            axisLine: {
              lineStyle: {
                color: '#efefef',
                width: 1,
              },
            },

            axisTick: {
              show: false,
            },
            data: xaxisData,
          },
        ],
        yAxis: [
          {
            type: 'value',
            axisTick: {
              show: false,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#efefef',
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: '#efefef',
              },
            },
            axisLabel: {
              show: true,
              color: '#000',
              fontSize: 14,
            },
          },
          {
            type: 'value',
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            splitLine: {
              show: false,
            },
            axisLabel: {
              show: true,
              formatter: '{value} %',
              color: '#000',
              fontSize: 14,
            },
          },
        ],
        series: yaxisData,
      };
      myChart.setOption(option);
      if (flash) this.lunboEcharts(myChart, xaxisData.length);
    },
    //轮播tootip
    lunboEcharts(echartsId, dataLen, currentIndex = -1) {
      clearInterval(this.timer);
      this.timer = setInterval(() => {
        echartsId.dispatchAction({
          type: 'downplay',
          seriesIndex: 0,
          dataIndex: currentIndex,
        });
        currentIndex = (currentIndex + 1) % dataLen;
        echartsId.dispatchAction({
          type: 'highlight',
          seriesIndex: 0,
          dataIndex: currentIndex,
        });
        echartsId.dispatchAction({
          type: 'showTip',
          seriesIndex: 0,
          dataIndex: currentIndex,
        });
      }, 3000);
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶浩成520

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值