目录
一、运行环境
常用环境:window+vue
二、操作步骤
1.安装echarts
npm install echarts -S
可能出现错误如下:
出现上图原因可能是npm版本问题报错,可尝试在后面加上 --legacy-peer-deps
npm install echarts -S --legacy-peer-deps
成功
2.引用echarts包
import * as echarts from 'echarts'
3.局部引用
<template>
<div :id="id" ref="chart"></div>
</template>
<script>
import * as echarts from 'echarts'
export default {
name: 'LineChart',
props: {
id: {
type: String,
default: 'chartBox'
}
},
data () {
return {
myChart: null
}
},
methods: {
initCharts () {
this.myChart = echarts.init(this.$refs.chart)
// 绘制图表
this.myChart.setOption({
title: { text: '在Vue中使用echarts' },
tooltip: {},
xAxis: {
data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
})
}
},
mounted () {
this.initCharts()
}
}
</script>
<style scoped>
</style>
四、结果展示
五、简单总结
1.简单应用实现,局部引用即可。
2.注意用 import * as echarts from 'echarts'