在vue项目中使用Echarts

参考图在这里插入图片描述

一、创建自己的工程和安装 echarts
npm install echarts --save

二、引入方式
挂载到mi n.js全局中
import echarts from “echarts”;
Vue.prototype.$echarts = echarts;

在这里插入图片描述
三、在页面中使用
在这里插入图片描述在这里插入图片描述

<template>
  <div id="app">
    <div id="main" style="width: 600px;height:400px;"></div>
  </div>
</template>

<script>
export default {
  name: "app",
  methods: {
    drawChart() {
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById("main"));
      // 指定图表的配置项和数据
      let option = {
        backgroundColor: "#011c3a",
        xAxis: {
          data: [
            "人员1",
            "人员2",
            "人员3",
            "人员4",
            "人员5、人员6",
            "人员7",
            "人员8",
          ],
          axisLine: {
            lineStyle: {
              color: "#3d5269",
            },
          },
          axisLabel: {
            color: "#fff",
            fontSize: 14,
          },
        },
        yAxis: {
          name: "单位:次",
          nameTextStyle: {
            color: "#fff",
            fontSize: 16,
          },
          axisLine: {
            lineStyle: {
              color: "#3d5269",
            },
          },
          axisLabel: {
            color: "#fff",
            fontSize: 16,
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#2d3d53",
            },
          },
          interval: 500,
        },
        series: [
          {
            type: "bar",
            barWidth: 50,
            itemStyle: {},
            label: {
              normal: {
                show: true,
                fontSize: 18,
                fontWeight: "bold",
                color: "#ffffff",
                position: "top",
              },
            },
            data: [254, 3254, 1654, 2454, 4757, 2011, 1211],
          },
        ],
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
  },
  mounted() {
    this.drawChart();
  },
};
</script>


<style scoped>
</style>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值