图表刷新
This commit is contained in:
parent
3fa4900eb9
commit
f802825e86
@ -2,7 +2,7 @@
|
|||||||
<div ref="chartRef" :style="{ height, width }"></div>
|
<div ref="chartRef" :style="{ height, width }"></div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { ref, reactive, watchEffect, watch } from 'vue';
|
import { ref, reactive, watchEffect } from 'vue';
|
||||||
import { cloneDeep } from 'lodash';
|
import { cloneDeep } from 'lodash';
|
||||||
import { useEcharts } from '@/hooks/useEcharts';
|
import { useEcharts } from '@/hooks/useEcharts';
|
||||||
|
|
||||||
@ -66,18 +66,6 @@ export default {
|
|||||||
props.chartData && initCharts();
|
props.chartData && initCharts();
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.chartData,
|
|
||||||
() => {
|
|
||||||
console.info('props.chartData变化', props.chartData);
|
|
||||||
props.chartData && initCharts();
|
|
||||||
},
|
|
||||||
{
|
|
||||||
deep: true,
|
|
||||||
immediate: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
function hexToRGBA(hex, alpha = 1) {
|
function hexToRGBA(hex, alpha = 1) {
|
||||||
let hexCode = hex.replace('#', '');
|
let hexCode = hex.replace('#', '');
|
||||||
if (hexCode.length === 3) {
|
if (hexCode.length === 3) {
|
||||||
@ -155,8 +143,8 @@ export default {
|
|||||||
seriesIndex: 0,
|
seriesIndex: 0,
|
||||||
showTooltip: true,
|
showTooltip: true,
|
||||||
});
|
});
|
||||||
getInstance()?.off('click', onClick);
|
// getInstance()?.off('click', onClick);
|
||||||
getInstance()?.on('click', onClick);
|
// getInstance()?.on('click', onClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClick(params) {
|
function onClick(params) {
|
||||||
|
@ -141,14 +141,13 @@ export const useEcharts = (elRef, theme = 'default') => {
|
|||||||
function setOptions(options = {}, clear = true) {
|
function setOptions(options = {}, clear = true) {
|
||||||
const mergedOptions = {
|
const mergedOptions = {
|
||||||
animation: true,
|
animation: true,
|
||||||
animationDuration: 3000,
|
animationDuration: 1000,
|
||||||
animationEasing: 'cubicOut',
|
animationEasing: 'cubicOut',
|
||||||
...unref(options),
|
...unref(options),
|
||||||
animationThreshold: 2000, // 数据量超过2000自动关闭动画
|
animationThreshold: 2000, // 数据量超过2000自动关闭动画
|
||||||
animationDelayUpdate: (idx) => idx * 50, // 数据项延迟
|
animationDelayUpdate: (idx) => idx * 50, // 数据项延迟
|
||||||
};
|
};
|
||||||
cacheOptions.value = mergedOptions;
|
cacheOptions.value = mergedOptions;
|
||||||
cacheOptions.value = options;
|
|
||||||
if (unref(elRef)?.offsetHeight === 0) {
|
if (unref(elRef)?.offsetHeight === 0) {
|
||||||
useTimeoutFn(() => {
|
useTimeoutFn(() => {
|
||||||
setOptions(unref(getOptions));
|
setOptions(unref(getOptions));
|
||||||
@ -164,7 +163,6 @@ export const useEcharts = (elRef, theme = 'default') => {
|
|||||||
}
|
}
|
||||||
clear && chartInstance?.clear();
|
clear && chartInstance?.clear();
|
||||||
chartInstance?.setOption(unref(getOptions));
|
chartInstance?.setOption(unref(getOptions));
|
||||||
|
|
||||||
// 立即绑定事件
|
// 立即绑定事件
|
||||||
chartInstance.off('click');
|
chartInstance.off('click');
|
||||||
chartInstance.on('click', handleMapClick);
|
chartInstance.on('click', handleMapClick);
|
||||||
|
@ -1,34 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<custom-echart-line :chart-data="dataList" height="100%" :option="state.option" />
|
<custom-echart-line ref="lineCharts" :chart-data="state.data" height="100%" :option="state.option" />
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
let dataList = reactive([
|
let dataList = [
|
||||||
{
|
{ value: 10, name: '2020' },
|
||||||
value: 10,
|
{ value: 66, name: '2021' },
|
||||||
name: '2020',
|
{ value: 100, name: '2022' },
|
||||||
},
|
{ value: 120, name: '2023' },
|
||||||
{
|
{ value: 150, name: '2024' },
|
||||||
value: 66,
|
{ value: 80, name: '2025' },
|
||||||
name: '2021',
|
];
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 100,
|
|
||||||
name: '2022',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 120,
|
|
||||||
name: '2023',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 150,
|
|
||||||
name: '2024',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 80,
|
|
||||||
name: '2025',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
option: {
|
option: {
|
||||||
color: ['#35D0C0'],
|
color: ['#35D0C0'],
|
||||||
@ -76,35 +58,19 @@ const state = reactive({
|
|||||||
},
|
},
|
||||||
data: dataList,
|
data: dataList,
|
||||||
});
|
});
|
||||||
|
const lineCharts = ref(null);
|
||||||
const refresData = () => {
|
const refresData = () => {
|
||||||
console.info('landPatrol********************refresData');
|
state.data = [
|
||||||
state.data = dataList = reactive([
|
{ value: 5, name: '2020' },
|
||||||
{
|
{ value: 36, name: '2021' },
|
||||||
value: 20,
|
{ value: 70, name: '2022' },
|
||||||
name: '2020',
|
{ value: 56, name: '2023' },
|
||||||
},
|
{ value: 70, name: '2024' },
|
||||||
{
|
{ value: 20, name: '2025' },
|
||||||
value: 86,
|
];
|
||||||
name: '2021',
|
|
||||||
},
|
// console.info('landPatrol********************refresData', dataList);
|
||||||
{
|
lineCharts.value && lineCharts.value.refreshCharts(state.data);
|
||||||
value: 120,
|
|
||||||
name: '2022',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 140,
|
|
||||||
name: '2023',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 170,
|
|
||||||
name: '2024',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 100,
|
|
||||||
name: '2025',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user