mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
refactor: improve NetworkChart x-axis tick formatting and interval
This commit is contained in:
parent
296b15a7d4
commit
c58b79e6d2
@ -4,7 +4,6 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
|
|||||||
import { ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart"
|
import { ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart"
|
||||||
import { fetchMonitor } from "@/lib/nezha-api"
|
import { fetchMonitor } from "@/lib/nezha-api"
|
||||||
import { cn, formatTime } from "@/lib/utils"
|
import { cn, formatTime } from "@/lib/utils"
|
||||||
import { formatRelativeTime } from "@/lib/utils"
|
|
||||||
import { NezhaMonitor, ServerMonitorChart } from "@/types/nezha-api"
|
import { NezhaMonitor, ServerMonitorChart } from "@/types/nezha-api"
|
||||||
import { useQuery } from "@tanstack/react-query"
|
import { useQuery } from "@tanstack/react-query"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
@ -264,12 +263,22 @@ export const NetworkChartClient = React.memo(function NetworkChart({
|
|||||||
<CartesianGrid vertical={false} />
|
<CartesianGrid vertical={false} />
|
||||||
<XAxis
|
<XAxis
|
||||||
dataKey="created_at"
|
dataKey="created_at"
|
||||||
tickLine={false}
|
tickLine={true}
|
||||||
|
tickSize={3}
|
||||||
axisLine={false}
|
axisLine={false}
|
||||||
tickMargin={8}
|
tickMargin={8}
|
||||||
minTickGap={32}
|
minTickGap={80}
|
||||||
interval={"preserveStartEnd"}
|
interval={0}
|
||||||
tickFormatter={(value) => formatRelativeTime(value)}
|
ticks={processedData
|
||||||
|
.filter((item) => {
|
||||||
|
const date = new Date(item.created_at)
|
||||||
|
return date.getMinutes() === 0 && date.getHours() % 3 === 0
|
||||||
|
})
|
||||||
|
.map((item) => item.created_at)}
|
||||||
|
tickFormatter={(value) => {
|
||||||
|
const date = new Date(value)
|
||||||
|
return `${date.getHours()}:00`
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<YAxis tickLine={false} axisLine={false} tickMargin={15} minTickGap={20} tickFormatter={(value) => `${value}ms`} />
|
<YAxis tickLine={false} axisLine={false} tickMargin={15} minTickGap={20} tickFormatter={(value) => `${value}ms`} />
|
||||||
<ChartTooltip
|
<ChartTooltip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user