<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-20 13:08': 1711, '2024-06-21 13:08': 294, '2024-06-22 13:08': 49,
    '2024-06-23 13:08': 19, '2024-06-24 13:08': 6, '2024-06-25 13:08': 5,
    '2024-06-26 13:08': 1, '2024-06-27 13:08': 0, '2024-06-28 13:08': 0,
    '2024-06-29 13:08': 0, '2024-06-30 13:08': 1, '2024-07-01 13:08': 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', 
    itemStyle: { color: '#91cc75' }
  }]
};

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

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