溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue+echarts怎么實帶漸變效果的折線圖

發(fā)布時間:2022-04-02 13:43:28 來源:億速云 閱讀:184 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“vue+echarts怎么實帶漸變效果的折線圖”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“vue+echarts怎么實帶漸變效果的折線圖”吧!

效果如下:

vue+echarts怎么實帶漸變效果的折線圖

1、安裝echarts

npm install echarts --save

2、引入echarts

import echarts from "echarts";
//修改原型鏈,可在全局使用
Vue.prototype.$echarts = echarts;

3、創(chuàng)建圖表 首先需要在 HTML 中創(chuàng)建圖表的容器

<div id="echarts_coverage"></div>
// css  圖表的容器必須指定寬高
#echarts_coverage{
      width: 400px;
      height: 200px;
}

4、渲染圖表

<script>
export default {
  mounted() {
    this.initLineChart();
  },
  methods: {
    initLineChart() {
      let data = [
        {
          dateStr: "2019第1季度",
          numberStr: 10,
        },
        {
          dateStr: "2019第1季度",
          numberStr: 50,
        },
        {
          dateStr: "2019第1季度",
          numberStr: 35,
        },
        {
          dateStr: "2019第1季度",
          numberStr: 92,
        },
        {
          dateStr: "2019第1季度",
          numberStr: 70,
        },
        {
          dateStr: "2019第1季度",
          numberStr: 80,
        },
      ];
      let lineData = {};
      lineData.label = data.map((item) => item.dateStr);
      lineData.data = data.map((item) => item.numberStr);
      let chart = this.$echarts.init(
        document.getElementById("echarts_coverage")
      );
      let option = {
        color: ["#3DB821"],
        tooltip: {
          trigger: "axis",
        },
        grid: {
          left: "3%",
          right: "5%",
          bottom: "8%",
          top: "20%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          offset: 6,
          axisLine: { lineStyle: { color: " #CCCCCC" } },
          axisTick: {
            show: false,
          },
          axisLabel: {
            interval: 0,
            rotate: 18,
            textStyle: {
              color: "#000",
              fontStyle: "normal",
              fontFamily: "微軟雅黑",
              fontSize: 13,
              margin: 10,
            },
          },
          data: lineData.label,
        },
        yAxis: {
          type: "value",
          name: "(%)",
          nameTextStyle: {
            align: "right",
            color: "#4D4D4D",
          },
          axisLine: {
            show: false,
            lineStyle: { color: "#CCCCCC" },
          },
          axisTick: { show: false },
          splitLine: {
            show: true,
            lineStyle: { type: "dashed", color: "#CCCCCC" },
          },
          axisLabel: {
            textStyle: {
              color: "#4D4D4D",
              fontSize: 14,
            },
          },
        },
        series: [
          {
            name: "數(shù)量",
            type: "line",
            stack: "總量",
            // symbol: "circle",
            symbolSize: 8,
            minInterval: 6,
            data: lineData.data,
            smooth: false,
            areaStyle: {
              normal: {
                color: {
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#3DB821", // 0% 處的顏色
                    },
                    {
                      offset: 0.5,
                      color: "rgba(51,180,21,.5)", // 100% 處的顏色
                    },
                    {
                      offset: 1,
                      color: "rgba(51,180,21,.1)", // 100% 處的顏色
                    },
                  ],
                  globalCoord: false, // 缺省為 false
                },
              },
            },
          },
        ],
      };
      chart.setOption(option);
    },
  },
};
</script>

到此,相信大家對“vue+echarts怎么實帶漸變效果的折線圖”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI