按照网上搜的改了下代码,只能看见两条轴,没有数据,请问是代码哪里有问题吗?
data(){
xData: [],
yData: [],
tableData: [],
}
//获取所有库存物资
async getStockList() {
const {data: res} = await this.$http.get("allStock", {params: this.queryInfo});
this.stockList = res.data;//库存列表
this.total = res.numbers;//总用库存
this.xData = [];
this.yData = [];
const $this = this;
//构建表格条形统计图的数据
this.tableData.forEach(function(e) {
console.log(e)
$this.xData.push(e.itemname);
$this.yData.push(e.numbers);
});
//重新绘制表格
this.getEchartData();
},
getEchartData(){
var myChart = echarts.init(document.getElementById('tiaoxing'));
var option = {
title: {
text: "库存条形图"
},
tooltip: {},
legend: {//图例
data: ["库存量"]
},
xAxis: {
//x轴设置
data: this.xData
},
yAxis: {},
series: [
{
name: "库存量",
data: this.yData, //y即接口方法传递过来的参数也是y轴的数据(x等同于res.data.yData)
type: "bar", //类型
},
],
};
myChart.setOption(option); //通过setOption()方法生成图表
},
mounted() {
this.getEchartData();
},