/** * 根据位置获取这个点在图表的哪个轴线上 * @param offsetX * @param offsetY */ export function getXAxisAndYAxisByPosition(chart, offsetX, offsetY, seriesIndex = 0) { const pointInPixel = [offsetX, offsetY] if ( chart.containPixel( { seriesIndex: 0 }, pointInPixel ) ) { const [xAxis, yAxis] = chart.convertFromPixel({ seriesIndex }, pointInPixel) return [xAxis, yAxis] } return null } /** * 将图表导出为图片 * @param {import("echarts").ECharts} chartInstance * @param {'png' | 'jpeg' | 'svg'} type */ export function exportEchartImg(chartInstance, type = 'png', backgroundColor = '#022024') { const dataURL = chartInstance.getDataURL({ type, pixelRatio: 2, backgroundColor }); const link = document.createElement('a') link.style.display = 'none' link.href = dataURL link.setAttribute('download', 'export.png') document.body.appendChild(link) link.click() document.body.removeChild(link) //下载完成移除元素 }