[STYLE] 優化機台日誌溫度圖表顯示
1. 修改機台溫度數據 API,改為傳送毫秒級時間戳記,以支援 ApexCharts 時間軸。 2. 將圖表橫軸類型改為 datetime,解決時間標籤重疊擁擠的問題。 3. 隱藏 ApexCharts 預設的無障礙輔助文字。 4. 優化提示框 (Tooltip) 顯示格式,改為顯示完整年月日時分秒,並自定義標題。 5. 關閉圖表動畫以提升側邊欄載入效能。
This commit is contained in:
parent
2f455cbd45
commit
dd641a2fc1
@ -257,10 +257,10 @@ class MachineController extends AdminController
|
||||
->oldest()
|
||||
->get();
|
||||
|
||||
$chartData = [
|
||||
'labels' => $logs->pluck('created_at')->map(fn($date) => $date->format('Y-m-d H:i:s'))->toArray(),
|
||||
'values' => $logs->map(fn($log) => (int) ($log->context['temp'] ?? 0))->toArray(),
|
||||
];
|
||||
$chartData = $logs->map(fn($log) => [
|
||||
'x' => $log->created_at->getTimestamp() * 1000,
|
||||
'y' => (int) ($log->context['temp'] ?? 0),
|
||||
])->values()->toArray();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
||||
@ -106,15 +106,17 @@
|
||||
const options = {
|
||||
series: [{
|
||||
name: "{{ __('Temperature') }}",
|
||||
data: chartData.values
|
||||
data: chartData
|
||||
}],
|
||||
chart: {
|
||||
id: 'temp-chart',
|
||||
type: 'area',
|
||||
height: 200,
|
||||
toolbar: { show: false },
|
||||
zoom: { enabled: false },
|
||||
animations: { enabled: true },
|
||||
background: 'transparent'
|
||||
animations: { enabled: false }, // 關閉動畫以減少渲染負擔
|
||||
background: 'transparent',
|
||||
accessibility: { enabled: false } // 隱藏無障礙輔助文字
|
||||
},
|
||||
colors: ['#06b6d4'],
|
||||
fill: {
|
||||
@ -137,18 +139,18 @@
|
||||
padding: { left: 10, right: 10 }
|
||||
},
|
||||
xaxis: {
|
||||
categories: chartData.labels,
|
||||
type: 'datetime',
|
||||
labels: {
|
||||
show: true,
|
||||
style: { colors: '#94a3b8', fontSize: '10px', fontWeight: 600 },
|
||||
formatter: (val) => {
|
||||
if (!val) return '';
|
||||
return val.split(' ')[1].substring(0, 5); // 僅顯示 HH:mm
|
||||
}
|
||||
datetimeUTC: false,
|
||||
format: 'HH:mm',
|
||||
hideOverlappingLabels: true,
|
||||
},
|
||||
axisBorder: { show: false },
|
||||
axisTicks: { show: false },
|
||||
tooltip: { enabled: false }
|
||||
tooltip: { enabled: false },
|
||||
tickAmount: 6 // 強制限制標籤數量避免擁擠
|
||||
},
|
||||
yaxis: {
|
||||
labels: {
|
||||
@ -158,7 +160,15 @@
|
||||
},
|
||||
tooltip: {
|
||||
theme: isDark ? 'dark' : 'light',
|
||||
x: { formatter: (val) => val }
|
||||
x: {
|
||||
show: true,
|
||||
format: 'yyyy/MM/dd HH:mm:ss'
|
||||
},
|
||||
y: {
|
||||
title: {
|
||||
formatter: (seriesName) => seriesName + ': '
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user