vehicle-monitor/src/utils/chart.ts

41 lines
973 B
TypeScript
Raw Normal View History

2025-03-13 23:01:44 +08:00
import { useDebounceFn, useEventListener } from '@vueuse/core';
2025-03-14 15:25:47 +08:00
2025-03-15 16:38:44 +08:00
import echarts from '@/plugins/echarts';
2025-03-12 09:42:48 +08:00
/** 通用重置图表样式 */
2025-03-14 15:25:47 +08:00
export const debounceChart = (myChart: echarts.ECharts | undefined) => {
2025-03-13 23:01:44 +08:00
const debounceFn = useDebounceFn(() => {
2025-03-13 18:39:39 +08:00
myChart!.resize();
2025-03-13 23:01:44 +08:00
}, 500);
useEventListener(window, 'resize', debounceFn);
2025-03-13 18:39:39 +08:00
};
/** 数字格式化 */
export const formatter = (number: any) => {
2025-05-15 23:10:31 +08:00
const numbers = number?.toString().split('').reverse();
2025-03-13 18:39:39 +08:00
const segs = [];
while (numbers.length) segs.push(numbers.splice(0, 3).join(''));
return segs.join(',').split('').reverse().join('');
2025-03-12 09:42:48 +08:00
};
2025-03-15 16:38:44 +08:00
/** 颜色渲染 */
export const graphicLinearGradient = (
color1: string,
color2: string,
coordinate: Array<number> = [0, 0, 0, 1]
) => {
return new echarts.graphic.LinearGradient(
coordinate[0],
coordinate[1],
coordinate[2],
coordinate[3],
[
{ offset: 0, color: color1 },
{ offset: 1, color: color2 },
]
);
};