<div class="box">
<div class="chart" id="Barline">div>
<div class="chart" id="Pie">div>
div>
div>
<script>
const App = {
data() {
return {
counter: 0
}
},
mounted() {
{
this.initChart('#Barline')
this.initChart('#Pie')
}
this.Barline()
},
methods: {
initChart(name) {
const chart = echarts.init(document.querySelector(name))
const data = ['Babycar', 'Flydog', 'Mdd', 'Shidanli', 'Dangon']
const option = {
textStyle: {
fontFamily: '字魂方方先锋体'
},
title: {
text: '折柱混合图(mixin)',
left: 'center',
top: '1%',
},
grid: {
top: '15%',
left: '3%',
right: '3%',
bottom: '6%',
containLabel: true
},
legend: [],
xAxis: {
type: 'category',
data,
boundaryGap: () => {
console.log(option)
},
},
yAxis: {
type: 'value',
interval: 50
}
}
chart.setOption(option)
},
Barline() {
const chart = echarts.init(document.querySelector('#Barline'))
const option = {
series: [
{
type: 'bar',
name: 'Score',
stack: 'total',
data: [100, 120, 130, 80, 100]
},
{
type: 'bar',
name: 'num',
data: [80, 100, 150, 150, 130]
},
{
type: 'line',
name: 'line',
stack: 'total',
data: [100, 120, 130, 80, 100]
}
]
}
chart.setOption(option)
}
}
};
Vue.createApp(App).mount('#app');
script>
人家是个数组类型呀,
1.你可以在initChart 函数里面设一个变量获取值
2.或者当图表渲染后,再次设置属性