2024-10-29 16:32:32 +08:00
|
|
|
const dataProcessing = (arr: any[]) => {
|
|
|
|
|
return arr
|
2024-12-30 10:07:26 +08:00
|
|
|
.filter(item => typeof item === 'number' || (typeof item === 'string' && !isNaN(parseFloat(item))))
|
|
|
|
|
.map(item => (typeof item === 'number' ? item : parseFloat(item)))
|
2024-10-29 16:32:32 +08:00
|
|
|
}
|
|
|
|
|
|
2024-10-22 10:50:47 +08:00
|
|
|
// 处理y轴最大最小值
|
2024-09-29 18:15:54 +08:00
|
|
|
export const yMethod = (arr: any) => {
|
2024-12-30 10:07:26 +08:00
|
|
|
let numList = dataProcessing(arr)
|
|
|
|
|
let maxValue = 0
|
|
|
|
|
let minValue = 0
|
|
|
|
|
let max = 0
|
|
|
|
|
let min = 0
|
|
|
|
|
maxValue = Math.max(...numList)
|
|
|
|
|
minValue = Math.min(...numList)
|
2024-10-22 15:55:24 +08:00
|
|
|
if (maxValue > 1000 || minValue < -1000) {
|
2024-12-30 10:07:26 +08:00
|
|
|
max = Math.ceil(maxValue / 100) * 100
|
|
|
|
|
if (minValue == 0) {
|
|
|
|
|
min = 0
|
|
|
|
|
} else {
|
|
|
|
|
min = Math.floor(minValue / 100) * 100
|
2024-10-14 20:15:54 +08:00
|
|
|
}
|
2024-12-30 10:07:26 +08:00
|
|
|
} else if (maxValue < 60 && minValue > 40) {
|
|
|
|
|
max = 60
|
|
|
|
|
min = 40
|
|
|
|
|
} else if (maxValue == minValue && maxValue < 10 && minValue > 0) {
|
|
|
|
|
max = Math.ceil(maxValue / 10) * 10
|
|
|
|
|
min = Math.floor(minValue / 10) * 10
|
|
|
|
|
} else if (maxValue == minValue && maxValue != 0 && minValue != 0) {
|
|
|
|
|
max = Math.ceil(maxValue / 10 + 1) * 10
|
|
|
|
|
min = Math.floor(minValue / 10 - 1) * 10
|
2024-09-29 18:15:54 +08:00
|
|
|
} else {
|
2024-12-30 10:07:26 +08:00
|
|
|
max = Math.ceil(maxValue / 10) * 10
|
|
|
|
|
min = Math.floor(minValue / 10) * 10
|
2024-09-29 18:15:54 +08:00
|
|
|
}
|
2024-10-10 09:56:34 +08:00
|
|
|
|
|
|
|
|
if (maxValue > 0 && maxValue < 1) {
|
2024-12-30 10:07:26 +08:00
|
|
|
max = 1
|
|
|
|
|
} else if (max == 0 && minValue > -1 && minValue < 0) {
|
|
|
|
|
min = -1
|
2024-10-14 20:15:54 +08:00
|
|
|
}
|
2024-12-30 10:07:26 +08:00
|
|
|
return [min, max]
|
|
|
|
|
}
|
2024-10-22 15:55:24 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* title['A相','B相',]
|
|
|
|
|
* data[[1,2],[3,4]]
|
|
|
|
|
*/
|
2024-10-22 10:50:47 +08:00
|
|
|
// 导出csv文件
|
2024-10-22 15:55:24 +08:00
|
|
|
const convertToCSV = (title: object, data: any) => {
|
2024-12-30 10:07:26 +08:00
|
|
|
console.log('🚀 ~ convertToCSV ~ data:', data)
|
2024-10-22 15:55:24 +08:00
|
|
|
let csv = ''
|
|
|
|
|
// 添加列头
|
|
|
|
|
csv += ',' + title.join(',') + '\n'
|
|
|
|
|
// 遍历数据并添加到CSV字符串中
|
|
|
|
|
data?.map(item => {
|
|
|
|
|
csv += item.join(',') + '\n'
|
|
|
|
|
})
|
|
|
|
|
return csv
|
|
|
|
|
}
|
|
|
|
|
export const exportCSV = (title: object, data: any, filename: string) => {
|
|
|
|
|
const csv = convertToCSV(title, data)
|
|
|
|
|
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })
|
|
|
|
|
const link = document.createElement('a')
|
|
|
|
|
link.href = URL.createObjectURL(blob)
|
|
|
|
|
link.download = filename
|
|
|
|
|
link.click()
|
|
|
|
|
// 释放URL对象
|
|
|
|
|
URL.revokeObjectURL(link.href)
|
2024-10-22 10:50:47 +08:00
|
|
|
}
|