Vue2如何引入Echarts

目录

  • 一、NPM下载Echarts
  • 二、引入Echarts组件库
  • 三、使用Echarts


一、NPM下载Echarts

npm install echarts -S

二、引入Echarts组件库

// 引用Echarts
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;

Vue2如何引入Echarts_第1张图片

三、使用Echarts

<template>
  <el-row :gutter="12">
    <el-col :span="12">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>基础仪表盘span>
        div>
        <div id="basic_dashboard" style="width: 100%;height: 400px;">div>
      el-card>
    el-col>
  el-row>
template>

<script>
export default {
  created() {
    this.$nextTick(() => {
      this.basic_dashboard_type()
    })
  },
  data() {
    return {}
  },

  methods: {
    basic_dashboard_type() {
      var chartDom = document.getElementById('basic_dashboard');
      var myChart = this.$echarts.init(chartDom);
      var option = {
        tooltip: {
          formatter: '{a} 
{b} : {c}%'
}, series: [ { name: 'Pressure', type: 'gauge', detail: { formatter: '{value}' }, data: [ { value: 50, name: 'SCORE' } ] } ] } myChart.setOption(option); } } }
script>

Vue2如何引入Echarts_第2张图片

你可能感兴趣的:(vue,echarts,前端,javascript)