2025-03-14 16:47:42 +08:00
|
|
|
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',
|
2025-03-16 21:29:29 +08:00
|
|
|
grid: { top: '9%', right: 9, left: 9, bottom: '20%' },
|
2025-03-14 16:47:42 +08:00
|
|
|
tooltip: {},
|
|
|
|
legend: {
|
2025-03-16 21:29:29 +08:00
|
|
|
show: false,
|
2025-03-14 16:47:42 +08:00
|
|
|
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' },
|
2025-03-15 16:38:44 +08:00
|
|
|
splitLine: { show: true, lineStyle: { color: '#333', width: 1, type: 'solid' } },
|
2025-03-14 16:47:42 +08:00
|
|
|
splitArea: { show: false },
|
|
|
|
},
|
|
|
|
yAxis: { show: false, type: 'value' },
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
name: '入园',
|
|
|
|
type: 'line',
|
2025-03-15 16:38:44 +08:00
|
|
|
// data: [3, 9, 2, 8, 3, 4, 8, 2, 8, 3, 4, 8],
|
2025-03-14 16:47:42 +08:00
|
|
|
smooth: true,
|
|
|
|
symbol: 'circle',
|
|
|
|
symbolSize: 14,
|
|
|
|
itemStyle: { borderColor: '#16CEB9', borderWidth: 6, color: '#142745' },
|
|
|
|
lineStyle: { color: '#16CEB9', width: 6 },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '出园',
|
|
|
|
type: 'line',
|
2025-03-15 16:38:44 +08:00
|
|
|
// data: [2, 8, 3, 7, 1, 9, 18, 3, 7, 1, 9, 6],
|
2025-03-14 16:47:42 +08:00
|
|
|
smooth: true,
|
|
|
|
symbol: 'circle',
|
|
|
|
symbolSize: 14,
|
|
|
|
itemStyle: { borderColor: '#32C5FF', borderWidth: 6, color: '#142745' },
|
|
|
|
lineStyle: { color: '#32C5FF', width: 6 },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 渲染图表 */
|
|
|
|
export const renderEcharts = (element: Ref<HTMLDivElement>) => {
|
|
|
|
myChart = echarts.init(element.value, null, {
|
2025-03-15 16:38:44 +08:00
|
|
|
renderer: 'canvas',
|
2025-03-14 16:47:42 +08:00
|
|
|
devicePixelRatio: window.devicePixelRatio,
|
|
|
|
});
|
|
|
|
|
|
|
|
debounceChart(myChart);
|
|
|
|
|
|
|
|
myChart.setOption(option);
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 更新图表数据 */
|
|
|
|
export const updateChart = (option: Array<Array<number>>) => {
|
|
|
|
const series = myChart.getOption().series;
|
|
|
|
series[0].data = option[0];
|
|
|
|
series[1].data = option[1];
|
|
|
|
myChart.setOption({ series });
|
|
|
|
};
|