Commit 38375dac authored by xinzhedeai's avatar xinzhedeai

add:降雨量echarts

parent a1172362
<template> <template>
<n-card :bordered="false" class="rainfall-trend-card"> <div class="wrapper">
<div class="card-header"> <h2 class="card-title">近24小时降雨量变化趋势图</h2>
<h2 class="card-title">近24小时降雨量变化趋势图</h2> <div class="chart-wrapper">
<n-button size="small" type="text" class="collapse-btn"> <div class="chart-container" ref="chartRef"></div>
<n-icon><ChevronUp /></n-icon> 收起
</n-button>
</div> </div>
<div class="chart-container" ref="chartRef"></div> </div>
</n-card>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, onUnmounted, nextTick } from 'vue'; import { ref, onMounted, onUnmounted, nextTick } from "vue";
import * as echarts from 'echarts'; import * as echarts from "echarts";
import { ChevronUp } from '@vicons/ionicons5'; import { ChevronUp } from "@vicons/ionicons5";
const chartRef = ref<HTMLDivElement | null>(null); const chartRef = ref<HTMLDivElement | null>(null);
let chartInstance: echarts.ECharts | null = null; let chartInstance: echarts.ECharts | null = null;
...@@ -24,30 +21,36 @@ const initChart = () => { ...@@ -24,30 +21,36 @@ const initChart = () => {
chartInstance = echarts.init(chartRef.value); chartInstance = echarts.init(chartRef.value);
const hours = Array.from({ length: 24 }, (_, i) => `${i}:00`); const hours = Array.from({ length: 24 }, (_, i) => `${i}:00`);
const data = hours.map(() => Math.floor(Math.random() * 150) + 20); const data = hours.map(() => Math.floor(Math.random() * 150) + 20);
chartInstance.setOption({ chartInstance.setOption({
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, grid: { left: "3%", right: "4%", bottom: "3%", containLabel: true },
xAxis: { xAxis: {
type: 'category', data: hours, type: "category",
axisLine: { lineStyle: { color: '#4f6b95' } }, data: hours,
axisLabel: { color: '#a0b3d6', interval: 2 } axisLine: { lineStyle: { color: "#4f6b95" } },
axisLabel: { color: "#a0b3d6", interval: 2 },
}, },
yAxis: { yAxis: {
type: 'value', max: 300, type: "value",
axisLine: { lineStyle: { color: '#4f6b95' } }, max: 300,
axisLabel: { color: '#a0b3d6' }, axisLine: { lineStyle: { color: "#4f6b95" } },
splitLine: { lineStyle: { color: 'rgba(79, 107, 149, 0.2)' } } axisLabel: { color: "#a0b3d6" },
splitLine: { lineStyle: { color: "rgba(79, 107, 149, 0.2)" } },
}, },
series: [{ series: [
data, type: 'line', smooth: true, {
areaStyle: { data,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ type: "line",
{ offset: 0, color: 'rgba(54, 162, 235, 0.4)' }, smooth: true,
{ offset: 1, color: 'rgba(54, 162, 235, 0)' } areaStyle: {
]) color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: "rgba(54, 162, 235, 0.4)" },
{ offset: 1, color: "rgba(54, 162, 235, 0)" },
]),
},
lineStyle: { color: "rgba(54, 162, 235, 1)", width: 2 },
}, },
lineStyle: { color: 'rgba(54, 162, 235, 1)', width: 2 } ],
}]
}); });
}; };
...@@ -56,43 +59,48 @@ const resizeChart = () => chartInstance?.resize(); ...@@ -56,43 +59,48 @@ const resizeChart = () => chartInstance?.resize();
onMounted(() => { onMounted(() => {
nextTick(initChart); nextTick(initChart);
window.addEventListener('resize', resizeChart); window.addEventListener("resize", resizeChart);
}); });
onUnmounted(() => { onUnmounted(() => {
window.removeEventListener('resize', resizeChart); window.removeEventListener("resize", resizeChart);
chartInstance?.dispose(); chartInstance?.dispose();
}); });
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.rainfall-trend-card { .wrapper {
flex: 1; overflow: visible;
width: 4.6rem;
height: 3rem;
position: relative;
padding: 0.15rem; padding: 0.15rem;
background: var(--n-bg-color-secondary); padding-top: 0.45rem;
.card-header { .card-title {
position: absolute;
left: 0.25rem;
top: -0.15rem;
font-weight: 500;
font-size: 0.2rem;
color: #ffffff;
text-shadow: 0rem 0rem 0rem rgba(5, 38, 68, 0.5);
}
width: 100%;
margin-top: 0.3rem;
background-image: url("@/assets/jinrun/module-bg.png");
background-repeat: no-repeat;
.chart-wrapper {
display: flex; display: flex;
justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 0.15rem; justify-content: space-between;
width: 100%;
.card-title { height: 100%;
font-size: 0.18rem;
font-weight: 600;
color: var(--n-text-color-primary);
}
.collapse-btn {
font-size: 0.14rem;
color: var(--n-primary-color);
}
} }
.chart-container{
.chart-container {
width: 100%; width: 100%;
height: calc(100% - 0.4rem); height: 100%;
min-height: 1.2rem;
} }
} }
</style> </style>
\ No newline at end of file
...@@ -227,9 +227,8 @@ const navTo = () => { ...@@ -227,9 +227,8 @@ const navTo = () => {
<transition name="slide-left"> <transition name="slide-left">
<div class="left-modules" v-show="isLeftModulesVisible"> <div class="left-modules" v-show="isLeftModulesVisible">
<LeftDeviceStatus /> <LeftDeviceStatus />
<!-- <LeftDeviceStatus /> <LeftRainfallTrend />
<LeftDeviceStatus /> --> <!--
<!-- <LeftRainfallTrend />
<LeftOnlineMonitor /> --> <LeftOnlineMonitor /> -->
</div> </div>
</transition> </transition>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment