在jQuery裏面,實現一個折線圖,【前端統計圖】echarts實現單條折線圖
https://www.jianshu.com/p/0354a4f8c563。前端
如今要實現,Vue+Echarts實現一個折線圖,打開以前的mint項目:vue
1:在項目裏面安裝echartsnpm
cnpm install echarts --s
2:在須要用圖表的地方引入echarts
import echarts from 'echarts'
3:打開my.vue
繼續寫代碼,代碼以下:dom
<template> <!--爲echarts準備一個具有大小的容器dom--> <div id="main" style="width: 600px;height: 400px;"></div> </template> <script> import echarts from 'echarts' export default { name: '', data () { return { charts: '', opinion:['男','女'], opinionData:[ {value:335, name:'男'}, {value:310, name:'女'}, ] } }, methods:{ drawPie(id){ this.charts = echarts.init(document.getElementById(id)) this.charts.setOption({ tooltip: { trigger: 'item', }, legend: { orient: 'vertical', x: 'left', data:this.opinion }, series: [ { name:'性別', type:'pie', radius:['50%','70%'], avoidLabelOverlap: false, label: { normal: { show: false, position: 'center' }, emphasis: { show: true, textStyle: { fontSize: '30', fontWeight: 'blod' } } }, labelLine: { normal: { show: false } }, data:this.opinionData } ] }) } }, //調用 mounted(){ this.$nextTick(function() { this.drawPie('main') }) } } </script> <style scoped> * { margin: 0; padding: 0; list-style: none; } </style>
這個時候,能夠看到,加載出的餅狀圖了,後面能夠繼續進行完善。ide