const dataProcessing = (arr: any[]) => { return arr .filter(item => typeof item == 'number' || (typeof item == 'string' && !isNaN(parseFloat(item)))) .map(item => (typeof item == 'number' ? item : parseFloat(item))) } // 处理y轴最大最小值 export const yMethod = (arr: any) => { const numList = dataProcessing(arr); const maxValue = Math.max(...numList); const minValue = Math.min(...numList); const calculateBoundary = (value: number, base: number) => { return Math[value > 0? 'ceil' : 'floor'](value / base) * base; }; let max: number; let min: number; if (maxValue > 1000 || minValue < -1000) { max = calculateBoundary(maxValue, 100); min = minValue == 0? 0 : calculateBoundary(minValue, 100); } else if (maxValue < 60 && minValue > 40) { max = 60; min = 40; } else if (maxValue == minValue) { if (maxValue < 10 && minValue > 0) { max = calculateBoundary(maxValue, 10); min = calculateBoundary(minValue, 10); } else if (maxValue!== 0 && minValue!== 0) { max = calculateBoundary(maxValue / 10 + 1, 10); min = calculateBoundary(minValue / 10 - 1, 10); } } else { max = calculateBoundary(maxValue, 10); min = calculateBoundary(minValue, 10); } if (maxValue > 0 && maxValue < 1) { max = 1; } if (max == 0 && minValue > -1 && minValue < 0) { min = -1; } return [min, max]; }; /** * title['A相','B相',] * data[[1,2],[3,4]] */ // 导出csv文件 const convertToCSV = (title: object, data: any) => { // console.log('🚀 ~ convertToCSV ~ data:', data) 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) }