安装
npm install echarts --save
引入
import echarts from 'echarts'
Vue.echarts = Vue.prototype.$echarts = echarts
组件内使用
<tempmate>
<div ref="chart"></div>
</template>
export default {
name: 'chartDemo',
data () {
return {
myChart: null,
chartOption: {
// ...
}
}
},
created () {
this.$nextTick(() => {
this.initChart()
})
},
methods: {
initChart () {
this.myChart = this.$echarts.init(this.$refs.chart)
this.myChart.setOption(this.chartOption)
}
}
}