vue-cli 使用 echarts

npm 下载


npm install echarts --save

main.js 导入


import echarts from echarts

Vue.prototype.$echarts = echarts

app.vue 使用


<template>

  <div id="app">

    <div style="height:500px;" id="echarts"></div>

  </div>

</template>

<script>

export default {

  name: "App",

  data() {

    return {

      option: {

        title: {

          text: "ECharts 入门示例"

        },

        tooltip: {},

        xAxis: {

          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]

        },

        yAxis: {},

        series: [

          {

            name: "销量",

            type: "bar",

            data: [5, 20, 36, 10, 10, 20]

          }

        ]

      }

    };

  },

  mounted() {

    this.initCharts();

  },

  methods: {

    initCharts() {

      var myChart = this.$echarts.init(document.getElementById("echarts"));

      myChart.setOption(this.option);

    }

  }

};

</script>

<style>

#app {

  font-family: "Avenir", Helvetica, Arial, sans-serif;

  -webkit-font-smoothing: antialiased;

  -moz-osx-font-smoothing: grayscale;

  text-align: center;

  color: #2c3e50;

  margin-top: 60px;

}

</style>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。