1. 直接引入echarts
@H_404_3@先npm安装echarts@H_404_3@
开发:@H_404_3@
main.js@H_404_3@
方法都封装在这里
*/
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
...
...
mounted() {
this.$chart.line1('chart1');
},
2、使用vue-echarts
@H_404_3@先npm安装vue-echarts@H_404_3@
开发:@H_404_3@
main.js@H_404_3@
...
data: function() {
return {
orgOptions: {},}
},...
mounted() {
this.orgOptions = {
xAxis: {
type: 'category','Sun']
},yAxis: {
type: 'value'
},series: [{
data: [820,smooth: true
}]
}
}
总结
@H_404_3@以上所述是小编给大家介绍的Vue中使用Echarts的两种方式。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持。@H_404_3@ 原文链接:https://www.f2er.com/vue/31703.html