Echarts之折线图背景区域等级划分

需求:
在这里插入图片描述
鼠标移入:
在这里插入图片描述
实现:

<template>
  <div class="grade">
    <div id="grade-echart"></div>
    <div class="legend-list">
      <div class="legend-item" v-for="(item, index) in legendList" :key="index">
        <span
          class="item-color"
          :style="{ background: item.legendColor }"
        ></span>
        <span class="item-name">{{ item.legendName }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      legendList: [
        {
          legendName: "一级",
          legendColor: "#66FFFF",
        },
        {
          legendName: "二级",
          legendColor: "#FC5A5A",
        },
        {
          legendName: "三级",
          legendColor: "#00EA9C",
        },
        {
          legendName: "四级",
          legendColor: "#F3D74A",
        },
        {
          legendName: "五级",
          legendColor: "#4F9EFD",
        },
      ],
    };
  },
  methods: {
    initChart() {
      let colors = [
        "#66FFFF",
        "#FC5A5A",
        "#00EA9C",
        "#F3D74A",
        "#4F9EFD",
        "#FF923F",
        "#7662D6",
      ];
      let normolColor = "#A0B2D3";
      let option = {
        color: ["#FF923F"],
        tooltip: {
          trigger: "axis",
        },
        grid: {
          left: "3%",
          right: "3%",
          top: "8%",
          bottom: "2%",
          containLabel: true,
        },
        xAxis: {
          type: "category",

          data: [
            "00.00",
            "02:00",
            "04:00",
            "06:00",
            "08:00",
            "10:00",
            "12:00",
            "14:00",
            "16:00",
            "18:00",
            "20:00",
            "22:00",
            "24:00",
          ],
          axisLabel: {
            color: normolColor,
            fontSize: 16,
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          // boundaryGap: false, // type: "value" 设置
          boundaryGap: ["20%", "20%"], //type: "category" 设置
        },
        yAxis: {
          type: "value",
          axisLabel: {
            color: normolColor,
            fontSize: 16,
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: false,
          },
        },
        series: [
          {
            data: [0.2, 2, 5, 4, 6, 9, 6.5, 5, 4.2, 3.6, 2.5, 1.6, 5],
            type: "line",
            // lineStyle: {
            //   color: "#FF923F", //折线颜色
            // },
            markArea: {
              silent: true,
              data: [
                [
                  {
                    yAxis: 0,
                    itemStyle: {
                      color: colors[0],
                    },
                  },
                  {
                    yAxis: 2,
                  },
                ],
                [
                  {
                    yAxis: 2,
                    itemStyle: {
                      color: colors[1],
                    },
                  },
                  {
                    yAxis: 4,
                  },
                ],
                [
                  {
                    yAxis: 4,
                    itemStyle: {
                      color: colors[2],
                    },
                  },
                  {
                    yAxis: 6,
                  },
                ],
                [
                  {
                    yAxis: 6,
                    itemStyle: {
                      color: colors[3],
                    },
                  },
                  {
                    yAxis: 8,
                  },
                ],
                [
                  {
                    yAxis: 8,
                    itemStyle: {
                      color: colors[4],
                    },
                  },
                  {
                    yAxis: 10,
                  },
                ],
              ],
            },
          },
        ],
      };
      let myChart = this.$echarts.init(document.getElementById("grade-echart"));
      myChart.setOption(option);
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },
  },
  mounted() {
    this.initChart();
  },
};
</script>

<style lang="scss" scoped>
.grade {
  width: 700px;
  height: 380px;
  background: rgba(2, 15, 43, 0.7);
  #grade-echart {
    width: 700px;
    height: 350px;
  }
  .legend-list {
    width: 100%;
    display: flex;
    justify-content: center;
    color: #a0b2d3;
    .legend-item {
      margin: 0 15px;
      span {
        display: inline-block;
      }
      .item-color {
        width: 10px;
        height: 10px;
        margin-right: 5px;
      }
    }
  }
}
</style>

以上

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值