
代码:
<template>
<div class="echarts-container">
<div id="main"></div>
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
name: 'echarts-container',
data () {
return {
option: {
xAxis: {
type: 'category',
name: '姓名',
data: ['王一', '赵二', '张三', '李四', '王五', '赵六', '礼小七']
},
yAxis: {
type: 'value',
name: '完成数量'
},
series: [
{
data: [180, 230, 224, 218, 135, 147, 260],
type: 'line'
}
]
}
}
},
mounted () {
// const echartsDom = document.querySelector('#main')
const myChart = echarts.init(document.querySelector('#main'))
myChart.setOption(this.option)
}
}
</script>
<style scoped lang="less">
#main {
margin: 100px auto;
width: 380px;
height: 230px;
background-color: rgb(33, 194, 119);
}
</style>

该博客展示了一个Vue组件的实现,用于在网页中展示一个基于ECharts的折线图。代码包括了ECharts的引入、配置项的设定以及在挂载完成后初始化图表的过程。示例数据包括了姓名和完成数量两个维度,用于绘制折线图。
590

被折叠的 条评论
为什么被折叠?



