return {
radarChart: null,
arr1: [4200, 3000, 20000, 35000, 50000, 18000],
arr2: [5000, 14000, 28000, 26000, 42000, 21000]
}
},methods:{
updataChart() {
const val1 = [1000, 3100, 2800, 3000, 48000, 28000]
const val2 = [8000, 18000, 20000, 36000, 38000, 21000]
console.log(() => {
if (random != 0) {
return val1
} else {
return this.arr1
}
})
setInterval(() => {
const random = Math.round(Math.random())
const option = {
series: {
data: [
{
value: function(){
if (random != 0) {
return val1
} else {
return this.arr1
}
}
},
{
value: function(){
if (random != 0) {
return val2
} else {
return this.arr2
}
}
}
]
}
}
this.radarChart.setOption(option)
}, 2000);
}
}
random 只是生成 0-1之间的随机数。要用的话 * 一个数 比如 (Math.random()*10)+1
https://www.runoob.com/jsref/jsref-random.html
value的值应该是一个数组,你的是一个函数,是一个函数,是一个函数。你应该写一个立即执行函数,返回结果,这样value才能是立即函数返回的结果,或者直接value: random != 0 ? val2 : this.arr2
,和你函数的功能一样,代码还简洁