历史趋势修改

This commit is contained in:
zhujiyan
2024-07-03 19:31:29 +08:00
parent 43ed1fd1d2
commit 8f1290111e
5 changed files with 227 additions and 266 deletions

View File

@@ -225,71 +225,11 @@ const resizeObserver = new ResizeObserver(entries => {
}, 100)
}
})
const ExportChart: any = ref(null)
const handleExport = (arr: any) => {
// 使用ECharts的getOption方法获取当前图表的配置
const option = ExportOptions.value
const seriesData = option?.series
const xAxisList = option?.xAxis[0].data
if (seriesData && seriesData.length != 0) {
// 转换为CSV格式
let csvContent = '时间,'
const legendData = ExportOptions.value.legend.data
legendData.map((item: any, index: any) => {
index != legendData.length - 1 ? (csvContent += item.name + ',') : (csvContent += item.name + '\n')
})
let cellValue = ''
let list = []
legendData.map((item: any, index: any) => {
list.push('${seriesData[' + index + '].data[indexs]}')
})
console.log(seriesData[0].data.length)
seriesData.forEach((item: any, index: any) => {
item.data.map((vv: any, indexs: any) => {
cellValue += `${xAxisList[indexs]},`
// csvContent += `${item.name},${xAxisList[index]},${vv}\n`
// legendData.map((kk: any, indexss: any) => {
// indexs == legendData.length - 1 ? (cellValue += `${vv}\n`) : (cellValue += `${vv},`)
cellValue += `${seriesData[0].data[indexs]},${seriesData[1].data[indexs]},${seriesData[2].data[indexs]}s\n`
// })
// cellValue +=list.join(',')+'\n'
})
// csvContent += cellValue + `${xAxisList[index]}` + '\n'
})
let arrs = []
arrs = JSON.parse(JSON.stringify(new Set(cellValue.split('s'))))
console.log(arrs, '0000000000')
Array.from(arrs).map((item:any)=>{
cellValue +=item+'\n'.replace('s','')
})
console.log(cellValue, '去重后的数据')
return
csvContent += cellValue
// return
// 创建Blob对象并使用a标签下载
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })
const link = document.createElement('a')
if (link.download !== undefined) {
// 支持下载属性
const url = URL.createObjectURL(blob)
link.setAttribute('href', url)
link.setAttribute('download', '历史趋势.csv')
link.style.visibility = 'hidden'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
}
}
onMounted(() => {
initChart()
ExportChart.value = echarts.init(chartRef.value)
resizeObserver.observe(chartRef.value!)
})
defineExpose({ initChart, handleExport })
defineExpose({ initChart })
onBeforeUnmount(() => {
resizeObserver.unobserve(chartRef.value!)
chart?.dispose()