<template>
<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
<div style="width: 600px;height:400px;"/>
</template>
<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
export default {
data() {
return {
// 指定图表的配置项和数据
option: {
title: {
text: 'ECharts 入门'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
}
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
methods: {
initChart() { // 通过 echarts.init 方法初始化一个 echarts 实例并通过 setOption 方法生成一个简单的柱状图
this.chart = echarts.init(this.$el, 'macarons')
// 使用刚指定的配置项和数据显示图表。
this.chart.setOption(this.option)
}
}
}
</script>
Vue.js+ECharts:基础柱状图
最新推荐文章于 2023-08-24 16:27:32 发布