vehicle-monitor/src/views/smart-park/charts/right-sidebar.ts

108 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-02-26 22:04:47 +08:00
import 'echarts/lib/component/dataZoom';
import { type Ref, ref } from 'vue';
2025-02-26 22:37:30 +08:00
import echarts from '@/plugins/echarts';
2025-03-12 09:42:48 +08:00
import { debounceChart } from '@/utils/chart';
2025-02-26 22:37:30 +08:00
2025-03-13 23:01:44 +08:00
const option = ref<any>();
2025-02-27 13:41:42 +08:00
option.value = {
2025-02-26 22:04:47 +08:00
backgroundColor: 'transparent',
grid: { right: 10, left: 10, bottom: 20 },
title: {
text: '近7天车辆数据',
textStyle: { fontSize: 18, color: '#fff', fontWeight: 'lighter' },
},
tooltip: {},
legend: {
2025-02-26 22:10:38 +08:00
data: [
{ name: '出园', icon: 'rect', itemStyle: { color: '#4182FF' } },
{ name: '入园', icon: 'rect', itemStyle: { color: '#00FFFF' } },
],
2025-02-26 22:04:47 +08:00
icon: 'rect',
right: 0,
top: 0,
2025-02-27 13:41:42 +08:00
itemGap: 9,
2025-02-26 22:04:47 +08:00
orient: 'horizontal',
align: 'left',
textStyle: { fontSize: 14, color: '#fff' },
},
xAxis: {
type: 'category',
show: true,
data: ['02.01', '02.02', '02.03', '02.04', '02.05', '02.06', '02.07'],
itemStyle: { color: '#ccc' },
splitLine: {
show: true,
lineStyle: {
color: '#333',
width: 1,
type: 'solid', // 'solid' ||'dashed'||'dotted'
},
},
splitArea: {
show: false,
},
},
yAxis: { show: false, type: 'value' },
series: [
{
name: '入园',
type: 'line',
data: [3, 9, 2, 8, 3, 4, 8],
smooth: true,
symbol: 'circle',
symbolSize: 10,
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: '#4182FF' },
{ offset: 1, color: 'rgba(0,255,255,0)' },
],
},
},
itemStyle: { borderColor: '#00FFFF', borderWidth: 4, color: '#142745' },
lineStyle: { color: '#00FFFF', width: 3 },
},
{
name: '出园',
type: 'line',
data: [2, 8, 3, 7, 1, 9, 6],
smooth: true,
symbol: 'circle',
symbolSize: 10,
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: '#4182FF' },
{ offset: 1, color: 'rgba(0,255,255,0)' },
],
},
},
itemStyle: { borderColor: '#4182FF', borderWidth: 4, color: '#142745' },
lineStyle: { color: '#4182FF', width: 3 },
},
],
2025-02-27 13:41:42 +08:00
};
2025-02-26 22:04:47 +08:00
export const renderEcharts = (element: Ref<HTMLDivElement>) => {
2025-03-13 23:01:44 +08:00
const myChart: any = echarts.init(element.value, null, {
2025-02-26 22:04:47 +08:00
renderer: 'svg',
2025-02-27 13:41:42 +08:00
devicePixelRatio: window.devicePixelRatio,
2025-02-26 22:04:47 +08:00
});
2025-03-08 21:57:09 +08:00
2025-03-12 09:42:48 +08:00
debounceChart(myChart);
2025-03-08 21:57:09 +08:00
2025-02-26 22:04:47 +08:00
myChart.setOption(option.value);
};