vue项目中如何使用echarts
首先下载插件
npm i echarts -S
然后在main.js中引入插件
// 引入
import echarts from 'echarts'
// 注册
Vue.prototype.$echarts = echarts
在需要的组件中初始化图表
initChart () {
let echarts = this.$echarts.init(document.getElementById('charts'))
let option = {
xAxis: {
type: 'category',
data: ['4', '5', '6', '7', '8', '9', '10'],
splitLine: { show: true,
lineStyle: {
color: 'rgba(242,237,207,1)'
}
},
splitArea: { show: false },
axisTick: { show: false },
axisLine: {
lineStyle: { color: '#ccc', width: 0, height: 0 }
},
boundaryGap: false,
axisLabel: {
show: true,
textStyle: { color: '#ccc', fontSize: 12 }
}
},
yAxis: {
type: 'value',
splitLine: { show: false },
axisLine: {
lineStyle: { color: '#fff', width: 0 }
}
},
series: [{
lineStyle: {
normal: {
color: '#F6C20A'
}
},
smooth: true,
symbolSize: 4,
itemStyle: {
normal: {
label: {
show: false,
formatter: '{c}'
},
color: '#F6C20A',
width: 3
},
emphasis: {
label: {
show: true
}
}
},
data: [
{ value: 45 },
{ value: 50 },
{ value: 51 },
{ value: 50 },
{ value: 49 },
{ value: 48 },
{ value: 60, label: { show: true } }
],
type: 'line'
}],
grid: {
x: 40,
y: 30,
x2: 40,
y2: 70
}
}
echarts.setOption(option)
},
mounted () {
this.initChart()
}
最终展示的效果就是图下所示啦