Echarts折线图---带颜色过度---的小demo

效果:

代码:

<template>
  <div id="lineEchtar">
    <div id="lineEchtars" style="min-height: 300px; width: 100%"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
//import { abc } from "@/api/a/index";//接口在这里计入数据

export default {
  data() {
    return {
      myChart: null,
      xAxis: [],
      yAxis: []
    };
  },
  components: {},
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      abc().then(response => {//在这里获取数据  我这里先前端给了,后期res赋值就行
        this.xAxis =  ["2024-07-10","2024-07-09","2024-07-08","2024-07-07","2024-07-06","2024-07-05","2024-07-04"];
        this.yAxis = [150, 134, 224, 118, 235, 147, 260];
        this.interEchinterfun();   //得再接口异步执行后获取实例 要不获取不到
      });
    },
//Echarts图表方法
    interEchinterfun() {
      var chartDom = document.getElementById("lineEchtars");
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        //图例显示区域
        tooltip: {
          trigger: "axis",
          backgroundColor: "rgba(8,11,21,0.5)",
          textStyle: {
            color: "#fff"
          }
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: this.xAxis
        },
        yAxis: {
          type: "value",
          splitLine: {
            show: true, // 设置为 false 隐藏 Y 轴线
            lineStyle: {
              color: "#65C6E7",
              opacity: 0.2
            }
          }
        },
        series: [
          {
            data: this.yAxis,
            type: "line",
            smooth: true,//控制折线图圆弧行拐弯的
            areaStyle: {//颜色渐变
              normal: {
                color: {
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  //颜色过渡
                  colorStops: [
                    {
                      offset: 0.1,
                      color: "#00F4FD" // 线处的颜色
                    },
                    {
                      offset: 0.9,
                      color: "rgba(255,255,255,0.1)" // 坐标轴处的颜色
                    }
                  ]
                }
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }
};
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值