From 4c856596fa5cbc5a0b8d03678bbee9b8bb7a3d86 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Fri, 14 Mar 2025 16:47:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B7=A6=E4=BE=A7=E5=BA=95=E9=83=A8?= =?UTF-8?q?=E5=AE=8C=E6=88=90;=E6=B7=BB=E5=8A=A0=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/big-data/charts/left-middle.tsx | 27 ++++--- src/views/big-data/charts/leftBottom.tsx | 78 +++++++++++++++++++ .../big-data-left/components/left-bottom.vue | 55 ++++++++++++- .../big-data-left/components/left-middle.vue | 12 ++- src/views/smart-park/charts/right-sidebar.ts | 23 ++++-- .../smart-park-sidebar-right/index.vue | 28 ++++++- 6 files changed, 192 insertions(+), 31 deletions(-) create mode 100644 src/views/big-data/charts/leftBottom.tsx diff --git a/src/views/big-data/charts/left-middle.tsx b/src/views/big-data/charts/left-middle.tsx index cd748e4..00b08b5 100644 --- a/src/views/big-data/charts/left-middle.tsx +++ b/src/views/big-data/charts/left-middle.tsx @@ -44,6 +44,12 @@ option.value = { color: '#fff', formatter: '+{value}%', }, + data: [ + { + name: '环比变化', + detail: { valueAnimation: true, offsetCenter: ['0%', '-20%'] }, + }, + ], }, ], }; @@ -73,7 +79,9 @@ export const ChartProgress = defineComponent({ onMounted(() => { renderEcharts(myChart, chart); + updateChart(myChart, props); + watch( () => props.percent, () => { @@ -88,18 +96,9 @@ export const ChartProgress = defineComponent({ /** 更新图标数据 */ const updateChart = (myChart: Ref, props: any) => { - myChart.value?.setOption({ - series: [ - { - data: [ - { - name: '环比变化', - value: props.percent, - detail: { valueAnimation: true, offsetCenter: ['0%', '-20%'] }, - itemStyle: props.percent >= 20 ? itemStyles[0] : itemStyles[1], - }, - ], - }, - ], - }); + const series = myChart.value.getOption().series; + series[0].data[0].value = props.percent; + series[0].data[0].itemStyle = props.percent >= 20 ? itemStyles[0] : itemStyles[1]; + + myChart.value?.setOption({ series }); }; diff --git a/src/views/big-data/charts/leftBottom.tsx b/src/views/big-data/charts/leftBottom.tsx new file mode 100644 index 0000000..ede4b3a --- /dev/null +++ b/src/views/big-data/charts/leftBottom.tsx @@ -0,0 +1,78 @@ +import 'echarts/lib/component/dataZoom'; + +import type { Ref } from 'vue'; + +import echarts from '@/plugins/echarts'; +import { debounceChart } from '@/utils/chart'; + +let myChart = null; + +const option = { + backgroundColor: 'transparent', + grid: { top: 40, right: 0, left: 0, bottom: 24 }, + tooltip: {}, + legend: { + data: [ + { name: '出园', icon: 'rect', itemStyle: { color: '#32C5FF' } }, + { name: '入园', icon: 'rect', itemStyle: { color: '#16CEB9' } }, + ], + icon: 'rect', + right: 0, + top: 0, + itemGap: 9, + orient: 'horizontal', + align: 'left', + textStyle: { fontSize: 14, color: '#fff' }, + }, + xAxis: { + type: 'category', + show: true, + data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], + itemStyle: { color: '#ccc' }, + splitLine: { show: true, lineStyle: { color: '#333', width: 1, type: 'dotted' } }, + splitArea: { show: false }, + }, + yAxis: { show: false, type: 'value' }, + series: [ + { + name: '入园', + type: 'line', + data: [3, 9, 2, 8, 3, 4, 8, 2, 8, 3, 4, 8], + smooth: true, + symbol: 'circle', + symbolSize: 14, + itemStyle: { borderColor: '#16CEB9', borderWidth: 6, color: '#142745' }, + lineStyle: { color: '#16CEB9', width: 6 }, + }, + { + name: '出园', + type: 'line', + data: [2, 8, 3, 7, 1, 9, 18, 3, 7, 1, 9, 6], + smooth: true, + symbol: 'circle', + symbolSize: 14, + itemStyle: { borderColor: '#32C5FF', borderWidth: 6, color: '#142745' }, + lineStyle: { color: '#32C5FF', width: 6 }, + }, + ], +}; + +/** 渲染图表 */ +export const renderEcharts = (element: Ref) => { + myChart = echarts.init(element.value, null, { + renderer: 'svg', + devicePixelRatio: window.devicePixelRatio, + }); + + debounceChart(myChart); + + myChart.setOption(option); +}; + +/** 更新图表数据 */ +export const updateChart = (option: Array>) => { + const series = myChart.getOption().series; + series[0].data = option[0]; + series[1].data = option[1]; + myChart.setOption({ series }); +}; diff --git a/src/views/big-data/components/big-data-left/components/left-bottom.vue b/src/views/big-data/components/big-data-left/components/left-bottom.vue index 410020e..184e54f 100644 --- a/src/views/big-data/components/big-data-left/components/left-bottom.vue +++ b/src/views/big-data/components/big-data-left/components/left-bottom.vue @@ -1,13 +1,60 @@ - + - + diff --git a/src/views/big-data/components/big-data-left/components/left-middle.vue b/src/views/big-data/components/big-data-left/components/left-middle.vue index d370ffd..bac8e35 100644 --- a/src/views/big-data/components/big-data-left/components/left-middle.vue +++ b/src/views/big-data/components/big-data-left/components/left-middle.vue @@ -1,9 +1,10 @@ diff --git a/src/views/smart-park/charts/right-sidebar.ts b/src/views/smart-park/charts/right-sidebar.ts index 39dcfb4..0ca2711 100644 --- a/src/views/smart-park/charts/right-sidebar.ts +++ b/src/views/smart-park/charts/right-sidebar.ts @@ -1,12 +1,13 @@ import 'echarts/lib/component/dataZoom'; -import { type Ref, ref } from 'vue'; +import type { Ref } from 'vue'; import echarts from '@/plugins/echarts'; import { debounceChart } from '@/utils/chart'; -const option = ref(); -option.value = { +let myChart = null; + +const option = { backgroundColor: 'transparent', grid: { right: 10, left: 10, bottom: 20 }, title: { @@ -40,9 +41,7 @@ option.value = { type: 'solid', // 'solid' ||'dashed'||'dotted' }, }, - splitArea: { - show: false, - }, + splitArea: { show: false }, }, yAxis: { show: false, type: 'value' }, series: [ @@ -96,12 +95,20 @@ option.value = { }; export const renderEcharts = (element: Ref) => { - const myChart: any = echarts.init(element.value, null, { + myChart = echarts.init(element.value, null, { renderer: 'svg', devicePixelRatio: window.devicePixelRatio, }); debounceChart(myChart); - myChart.setOption(option.value); + myChart.setOption(option); +}; + +/** 更新图表数据 */ +export const updateChart = (option: any) => { + const series = myChart.getOption().series; + series[0].data = option.data1; + series[1].data = option.data2; + myChart.setOption({ series }); }; diff --git a/src/views/smart-park/components/smart-park-content/components/smart-park-sidebar-right/index.vue b/src/views/smart-park/components/smart-park-content/components/smart-park-sidebar-right/index.vue index ada6f9b..99bff17 100644 --- a/src/views/smart-park/components/smart-park-content/components/smart-park-sidebar-right/index.vue +++ b/src/views/smart-park/components/smart-park-content/components/smart-park-sidebar-right/index.vue @@ -1,12 +1,36 @@