前提:
后台接口返回两个数组一个key一个value。key为echarts的纵轴,value为横轴。
前端:
data(){
return{
option: {
title: {text: '节点利用率',subtext: '数据来自数据库统计'},
tooltip: {trigger: 'axis',axisPointer: {type: 'shadow'}},
legend: {data: ['2011年', '2012年']},
grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},
xAxis: { type: 'value',boundaryGap: [0, 0.01]},
yAxis: {
type: 'category',
data: ['1', '2','3','4','5','6']
},
series: [
{
name: '2011年',
type: 'bar',
data: [1,2,3,4,5,6]
},
]
}
}
}
method(){
// 根据软件名查效率
getSoftNameEfficiency(){
console.log(this.startTime)
console.log(this.stopTime)
console.log(this.softName)
var url="/calSoftName"
var params={
'softName':this.softName,
'startTime':this.startTime,
'stopTime':this.stopTime
}
this.$http.get(url,{params}).then(res=>{
console.log(res.data.value)
this.option.series[0].data=res.data.value
this.option.yAxis.data=res.data.key
console.log(this.option.series[0].data)
})
return this.option.series.data;
}
}