转换vue3 const option = JSON.parse(JSON.stringify(bcAttr)) let chartOption = {} let chartDimension = [] // 存放组织好的dimensions if (this._.has(option, '基础配置')) { chartOption = this._.merge(this.initialOption, option.基础配置) } if (this._.has(option, '数据')) { chartDimension = data.dimensions.map((item) => { return item }) // console.log('我是组织好的chartDimension', chartDimension) } chartOption.legend.data = bcDataset.yDimensions.map((item) => item) const maxarr = [] const valueArr = [[], [], [], [], []] option.数据.source.map((item) => { const arr = [] Object.values(item).forEach((ele) => { if (typeof ele === 'number') { arr.push(ele) } }) arr.sort((old, New) => { return old - New }) const obj = {} obj.name = item[bcDataset.xDimensions[0]] obj.max = arr[arr.length - 1] maxarr.push(obj) }) option.数据.source.map((item) => { const Array1 = [] Object.values(item).forEach((ele) => { if (typeof ele === 'number') { Array1.push(ele) } }) Array1.forEach((ele, index) => { valueArr.forEach((item, key) => { if (index == key) { valueArr[key].push(ele) } }) }) }) // console.log(maxarr) chartOption.radar.indicator = maxarr const optData = chartOption.legend.data const count = chartDimension.length - 1 for (let i = 0; i < count; i++) { // console.log(valueArr[i % valueArr.length]) const seriesObj = { type: 'radar', name: optData[i], areaStyle: { normal: { color: COLORLIST[i % COLORLIST.length], fontSize: 12 } }, symbolSize: 0, lineStyle: { normal: { color: COLORLIST[i % COLORLIST.length], width: 1, fontSize: 12 } }, data: [valueArr[i % valueArr.length]] } if (chartOption.series.length && chartOption.series[i]) { chartOption.series[i] = this._.merge(seriesObj, chartOption.series[i]) } else { chartOption.series.push(seriesObj) } }
时间: 2024-02-14 07:18:32 浏览: 184
vuecli4.x+element搭建的基础框架
在Vue3中,您可以按如下方式进行转换:
```javascript
const option = JSON.parse(JSON.stringify(bcAttr));
let chartOption = {};
let chartDimension = []; // 存放组织好的dimensions
if (Object.prototype.hasOwnProperty.call(option, '基础配置')) {
chartOption = this._.merge(this.initialOption, option.基础配置);
}
if (Object.prototype.hasOwnProperty.call(option, '数据')) {
chartDimension = data.dimensions.map((item) => {
return item;
});
// console.log('我是组织好的chartDimension', chartDimension)
}
chartOption.legend.data = bcDataset.yDimensions.map((item) => item);
const maxarr = [];
const valueArr = [[], [], [], [], []];
option.数据.source.map((item) => {
const arr = [];
Object.values(item).forEach((ele) => {
if (typeof ele === 'number') {
arr.push(ele);
}
});
arr.sort((old, New) => {
return old - New;
});
const obj = {};
obj.name = item[bcDataset.xDimensions[0]];
obj.max = arr[arr.length - 1];
maxarr.push(obj);
});
option.数据.source.map((item) => {
const Array1 = [];
Object.values(item).forEach((ele) => {
if (typeof ele === 'number') {
Array1.push(ele);
}
});
Array1.forEach((ele, index) => {
valueArr.forEach((item, key) => {
if (index == key) {
valueArr[key].push(ele);
}
});
});
});
// console.log(maxarr)
chartOption.radar.indicator = maxarr;
const optData = chartOption.legend.data;
const count = chartDimension.length - 1;
for (let i = 0; i < count; i++) {
// console.log(valueArr[i % valueArr.length])
const seriesObj = {
type: 'radar',
name: optData[i],
areaStyle: {
normal: {
color: COLORLIST[i % COLORLIST.length],
fontSize: 12
}
},
symbolSize: 0,
lineStyle: {
normal: {
color: COLORLIST[i % COLORLIST.length],
width: 1,
fontSize: 12
}
},
data: [valueArr[i % valueArr.length]]
};
if (chartOption.series.length && chartOption.series[i]) {
chartOption.series[i] = this._.merge(seriesObj, chartOption.series[i]);
} else {
chartOption.series.push(seriesObj);
}
}
```
需要注意的是,Vue3中的对象方法都在`Object.prototype`中定义,因此您需要使用`Object.prototype.hasOwnProperty`来检查属性是否存在。此外,您还需要注意箭头函数的写法和模板字符串的写法在Vue3中是否有所不同。
阅读全文