<template>
<div class="echarts">
<div id="mychart" style="width: 100%; height: 420px;"></div>
</div>
</template>
<script>
methods:{
//初始化echart
initChart() {
let _this = this
let chart = this.$echarts.init(document.getElementById('mychart'));
chart.setOption({
tooltip: {
trigger: 'item',
formatter: function (params) {
let name = params.name
let radarList = _this.radarData
for (let i = 0; i < params.data.value.length; i++) {
name += '<br/>' + radarList[i]['name'] + ' : ' + '最大值' + radarList[i]['max'] + ',当前值'
+ params.data.value[i];
}
return name;
}
},
grid: {
left: '1%',
right: '2%',
bottom: '3%',
containLabel: true
},
radar: {
name: {
textStyle: {
color: '#fff',
borderRadius: 3,
}
},
indicator: this.radarData,
},
series: [{
name: this.radarName,
type: 'radar',
areaStyle: {
color: "#5fb89f",
},
data: [
{
value: this.valueData,
name: this.radarName
},
]
}]
})
},
}
</script>
里面的formatter属性可以拿到值后重新定义,this.radarData中的this不能取到vue实例,需_this = this
才可以取到值,虽然获取到了值,但是不知道什么原因