我想取出数据库中的itemname和numbers放到x,y轴,请问应该怎么改呢?这是我现在的代码:
data() {
xData: [],
yData: [],
}
},
methods: {
async getStockList() {
const {data: res} = await this.$http.get("allStock", {params: this.queryInfo});
this.stockList = res.data;//用户列表
this.total = res.numbers;//总用户数
this.xData = data.itemname;
this.yData = data.numbers;
},
}
getEchartData() {
var myChart = echarts.init(document.getElementById('tiaoxing'));
let option = {
title: {
text: "库存条形图"
},
xAxis: {
data: this.xData
},
yAxis: {
type: 'value'
},
series: [
{
data: this.yData,
type: 'bar',
showBackground: true,
backgroundStyle: {
color: 'rgba(180, 180, 180, 0.2)'
}
}
]
}
myChart.setOption(option);
},
}
mounted() {
this.getEchartData();
},