Vue上使用Echart
1安装Echart
cnpm install echarts --save
PS E:\COLDDEMO\VueProject\FirstVue\myvue> cnpm install echarts --save √ Installed 1 packages √ Linked 1 latest versions √ Run 0 scripts √ All packages installed (2 packages installed from npm registry, used 7s, speed 1.41MB/s, json 2(18.66kB), tarball 9.22MB) PS E:\COLDDEMO\VueProject\FirstVue\myvue> npm list echarts
2项目页面引用Echart
import echarts from 'echarts'
export default { name: 'Home', mounted(){ this.SetEchart(); }, data () { return { msg: 'Welcome to 凌云木 Vue.js App' } }, methods: { SetEchart(){ // 基于准备好的dom,初始化echarts实例 let myChart = this.$echarts.init(document.getElementById('myChart')) // 绘制图表 var option = { title: { text: '郑州月最低生活费组成(单位:元)', }, tooltip : { trigger: 'axis', axisPointer : { // 坐标轴指示器,坐标轴触发有效 type : 'shadow' // 默认为直线,可选为:'line' | 'shadow' }, formatter: function (params) { var tar = params[1]; return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value; } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: { type : 'category', splitLine: {show:false}, data : ['总费用','房租','水电费','交通费','伙食费','日用品数'] }, yAxis: { type : 'value' }, series: [ { name: '辅助', type: 'bar', stack: '总量', itemStyle: { normal: { barBorderColor: 'rgba(0,0,0,0)', color: 'rgba(0,0,0,0)' }, emphasis: { barBorderColor: 'rgba(0,0,0,0)', color: 'rgba(0,0,0,0)' } }, data: [0, 1700, 1400, 1200, 300, 0] }, { name: '生活费', type: 'bar', stack: '总量', label: { normal: { show: true, position: 'inside' } }, data:[3900, 2200, 300, 200, 900, 300] } ] }; myChart.setOption(option); } } }
3启动项目
npm run dev
PS E:\COLDDEMO\VueProject\FirstVue\myvue> npm run dev> myvue@1.0.0 dev E:\COLDDEMO\VueProject\FirstVue\myvue > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js E:\COLDDEMO\VueProject\FirstVue\myvue\config 95% emitting DONE Compiled successfully in 5612ms
作者:凌雲木
链接:https://www.jianshu.com/p/45c32c65417a
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦