echarts雷达图 indicator如何用从后端传的数据
时间: 2024-03-09 16:49:10 浏览: 20
要使用后端传来的数据来设置 echarts 雷达图的 indicator,你需要在前端使用 Ajax 或者其他方式向后端请求数据,并将数据转换为 echarts 雷达图所需的格式。
假设后端返回的数据格式为:
```
[
{name: '指标1', max: 100},
{name: '指标2', max: 200},
{name: '指标3', max: 300},
{name: '指标4', max: 400},
{name: '指标5', max: 500}
]
```
你可以通过以下代码将数据转换为 echarts 雷达图的 indicator 格式:
```
var data = [
{name: '指标1', max: 100},
{name: '指标2', max: 200},
{name: '指标3', max: 300},
{name: '指标4', max: 400},
{name: '指标5', max: 500}
];
var indicatorData = [];
for (var i = 0; i < data.length; i++) {
indicatorData.push({
name: data[i].name,
max: data[i].max
});
}
option = {
// ...
radar: {
// ...
indicator: indicatorData
},
// ...
};
```
这样就可以使用后端传来的数据来设置 echarts 雷达图的 indicator 了。