欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue中引入echarts实现数据可视化

程序员文章站 2022-05-10 15:36:13
...

安装

npm install echarts -S

main.js全局引入

import echarts from 'echarts'
Vue.prototype.$echarts = echarts
<template>
  <div class="box">
    <div id="polyLineChart" :style="{width: '300px', height: '300px'}"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  mounted() {
    this.polyLineChart();
  },
  methods: {
    polyLineChart() {
      var myChart = this.$echarts.init(
        document.getElementById("polyLineChart")
      );
      var option = {
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
        },
        yAxis: {
          type: "value"
        },
        series: [
          {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: "line"
          }
        ]
      };
      myChart.setOption(option);
    }
  }
};
</script>

<style lang="less" scoped>
.box {
  padding: 30px;
  box-sizing: border-box;
}
</style>
相关标签: Module