这篇文章主要介绍了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......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......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 }] }}
登录后复制
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
关于VUE中常用的几种import(模块、文件)引入方式的介绍
关于VUE中常用的几种import(模块、文件)引入方式的介绍
以上就是Vue中使用Echarts的两种方式的介绍的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2747410.html