<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-19 21:36': 416, '2024-06-20 09:36': 796, '2024-06-20 21:36': 403,
    '2024-06-21 09:36': 236, '2024-06-21 21:36': 33, '2024-06-22 09:36': 29,
    '2024-06-22 21:36': 11, '2024-06-23 09:36': 10, '2024-06-23 21:36': 5,
    '2024-06-24 09:36': 10, '2024-06-24 21:36': 7, '2024-06-25 09:36': 1,
    '2024-06-25 21:36': 4, '2024-06-26 09:36': 6, '2024-06-26 21:36': 5,
    '2024-06-27 09:36': 5, '2024-06-27 21:36': 2, '2024-06-28 09:36': 1,
    '2024-06-28 21:36': 0, '2024-06-29 09:36': 1, '2024-06-29 21:36': 1
};

// --- 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: '#5470c6' },
    areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: 'rgba(84, 112, 198, 0.4)' }, { offset: 1, color: 'rgba(84, 112, 198, 0)' }])}
  }]
};

onMounted(() => {
  myChart = echarts.init(chartRef.value);
  myChart.setOption(option);
  window.addEventListener('resize', () => myChart.resize());
});

onUnmounted(() => {
  myChart?.dispose();
});
</script>