58 lines
1.5 KiB
Vue
58 lines
1.5 KiB
Vue
<template>
|
|
<div ref="chartRef" style="width: 100%; height: 400px;"></div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, onMounted, onUnmounted } from 'vue';
|
|
import * as echarts from 'echarts';
|
|
|
|
// --- 原始数据 ---
|
|
const originalData = {
|
|
'2024-06-22 17:10': 10, '2024-06-23 05:10': 1255, '2024-06-23 17:10': 801,
|
|
'2024-06-24 05:10': 281, '2024-06-24 17:10': 48, '2024-06-25 05:10': 65,
|
|
'2024-06-25 17:10': 30, '2024-06-26 05:10': 32, '2024-06-26 17:10': 16,
|
|
'2024-06-27 05:10': 7, '2024-06-27 17:10': 5, '2024-06-28 05:10': 2,
|
|
'2024-06-28 17:10': 1, '2024-06-29 05:10': 1, '2024-06-29 17:10': 1,
|
|
'2024-06-30 05:10': 4, '2024-06-30 17:10': 1, '2024-07-01 05:10': 4
|
|
};
|
|
|
|
// --- Y轴镜像转换 ---
|
|
const xAxisData = Object.keys(originalData);
|
|
const yAxisMirroredData = Object.values(originalData).reverse();
|
|
|
|
// --- ECharts 核心逻辑 ---
|
|
const chartRef = ref(null);
|
|
let myChart = null;
|
|
|
|
const option = {
|
|
title: {
|
|
text: '时间热度预测',
|
|
left: 'center'
|
|
},
|
|
tooltip: { trigger: 'axis' },
|
|
grid: { left: '3%', right: '4%', bottom: '10%', containLabel: true },
|
|
xAxis: {
|
|
type: 'category',
|
|
data: xAxisData,
|
|
axisLabel: { rotate: 30 }
|
|
},
|
|
yAxis: { type: 'value' },
|
|
series: [{
|
|
name: '热度',
|
|
data: yAxisMirroredData,
|
|
type: 'line',
|
|
smooth: true,
|
|
itemStyle: { color: '#fac858' }
|
|
}]
|
|
};
|
|
|
|
onMounted(() => {
|
|
myChart = echarts.init(chartRef.value);
|
|
myChart.setOption(option);
|
|
window.addEventListener('resize', () => myChart.resize());
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
myChart?.dispose();
|
|
});
|
|
</script> |