>  기사  >  웹 프론트엔드  >  Vue에서 Echarts를 사용하는 두 가지 방법 소개

Vue에서 Echarts를 사용하는 두 가지 방법 소개

不言
不言원래의
2018-07-03 14:35:571666검색

이 글은 Vue에서 Echarts를 사용하는 두 가지 방법을 주로 소개하며, 참고할만한 가치가 있습니다. 도움이 필요한 친구들은 참고하세요

npm 먼저 echarts를 설치하세요

npm install echarts --save

개발:

main.js

import myCharts from './comm/js/myCharts.js'
Vue.use(myCharts)
myCharts.js
/**
 * 各种画echarts图表的方法都封装在这里
 */
import echarts from 'echarts'
(function() {
  var chart = {};
  chart.install = function(vue) {
    vue.prototype.$chart = {
      //画一条简单的线
      line1: function(id) {
        this.chart = echarts.init(document.getElementById(id));
        this.chart.clear();
        const optionData = {
          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',
            smooth: true
          }]
        };
        this.chart.setOption(optionData);
      },
    }
  }
  if(typeof exports == 'object') {
    module.exports = chart
  }
})()
hello.vue
...
<p id="chart1"></p>
...
mounted() {
  this.$chart.line1(&#39;chart1&#39;);
},

2. vue-echarts

첫 번째 npm 설치 vue-echarts

npm install vue-echarts

개발:

main.js

import ECharts from &#39;vue-echarts/components/ECharts&#39;
import &#39;echarts/lib/chart/bar&#39;
import &#39;echarts/lib/component/tooltip&#39;
Vue.component(&#39;chart&#39;, ECharts)
hello.vue
...
<chart ref="chart1" :options="orgOptions" :auto-resize="true"></chart>
...
data: function() {
  return {
    orgOptions: {},
  }
},
...
mounted() {
  this.orgOptions = {
    xAxis: {
      type: &#39;category&#39;,
      data: [&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wed&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]
    },
    yAxis: {
      type: &#39;value&#39;
    },
    series: [{
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: &#39;line&#39;,
      smooth: true
    }]
  }
}

위는 이 글의 전체 내용입니다. , 모든 분들의 학습에 도움이 되기를 바랍니다. 더 많은 관련 내용을 보시려면 PHP 중국어 웹사이트를 주목해 주세요!

관련 권장 사항:

VUE


vue에서 일반적으로 사용되는 여러 가져오기 방법(모듈, 파일) 소개

에 대한 로그인 권한을 설정하는 방법

위 내용은 Vue에서 Echarts를 사용하는 두 가지 방법 소개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.