您好,欢迎来到筏尚旅游网。
搜索
您的当前位置:首页Vue中使用Echarts的两种方式的介绍

Vue中使用Echarts的两种方式的介绍

来源:筏尚旅游网

这篇文章主要介绍了Vue中使用Echarts的两种方式,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

1. 直接引入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('chart1');
},

2、使用vue-echarts

先npm安装vue-echarts

npm install vue-echarts

开发:

main.js

import ECharts from 'vue-echarts/components/ECharts'
import 'echarts/lib/chart/bar'
import 'echarts/lib/component/tooltip'
Vue.component('chart', ECharts)
hello.vue
...
<chart ref="chart1" :options="orgOptions" :auto-resize="true"></chart>
...
data: function() {
 return {
 orgOptions: {},
 }
},
...
mounted() {
 this.orgOptions = {
 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
 }]
 }
}

Copyright © 2019- efsc.cn 版权所有 赣ICP备2024042792号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务