Vue2.0 echarts的使用

一、安装依赖echarts

npm install echarts -S

二、图表创建
2.1在main.js中,引入(全局)

// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

2.2在.vue任意页面,如:index.vue
DOM代码

<div class="my-charts" ref="myChart"></div>

JS代码

export default {
  data() {
    return {};
  },
  mounted() {
    this.drawLine();
  },
  methods: {
    drawLine() {
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(this.$refs.myChart);
      // 绘制图表
      myChart.setOption({
        title: {
          text: "当周批转量和报备量",
          left: "5%"
        },
        tooltip: { trigger: "axis" },
        legend: {
          data: ["批转量", "报备量"],
          right: "5%"
        },
        grid: {
          left: "5%",
          right: "6%",
          bottom: "10%",
          containLabel: true
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: ["08-12", "08-13", "08-14", "08-15", "08-16", "08-17", "08-18"],
          axisLine: { lineStyle: { color: "#999", width: 0.1 } },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#999",
              width: 0.1
            }
          }
        },
        yAxis: {
          type: "value",
          axisLine: { lineStyle: { color: "#999", width: 0.1 } }
        },
        series: [
          {
            name: "批转量",
            type: "line",
            data: [5, 20, 36, 10, 10, 20, 0],
            areaStyle: {
              color: "rgb(237,252,245)"
            },
            smooth: true,
            itemStyle: {
              normal: {
                color: "#53e59d"
              }
            }
          },
          {
            name: "报备量",
            type: "line",
            data: [15, 0, 36, 10, 10, 0, 0],
            areaStyle: {
              color: "rgb(220,247,245)"
            },
            smooth: true,
            itemStyle: {
              normal: {
                color: "#43c4fd"
              }
            }
          }
        ]
      });
    }
  }
};
</script>

三、效果图如下:
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

刺心疯

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

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

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

打赏作者

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

抵扣说明:

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

余额充值