Skip to content

Commit

Permalink
chore: refactor chart x-axis tick format
Browse files Browse the repository at this point in the history
  • Loading branch information
OgDev-01 committed Jan 7, 2024
1 parent 642acd0 commit f9790d0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions components/CIResponsiveLine.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ResponsiveLine, Datum } from "@nivo/line";
import { format, parse } from "date-fns";
import { useRouter } from "next/router";

const CIResponsiveLine = ({ data }: Datum) => {
const router = useRouter();
const { range = 30 } = router.query;
return (
<>
<div style={{ height: 400, width: "100%" }}>
Expand All @@ -12,6 +14,7 @@ const CIResponsiveLine = ({ data }: Datum) => {
type: "linear",
stacked: true,
}}
xScale={{ type: "time", format: "%m/%d/%Y", precision: "day" }}
motionConfig="stiff"
curve="basis"
enableSlices="x"
Expand All @@ -27,14 +30,10 @@ const CIResponsiveLine = ({ data }: Datum) => {
legendOffset: -40,
legendPosition: "middle",
}}
xFormat="time:%m/%d/%Y"
axisBottom={{
tickSize: 0,
tickValues: 7,
tickPadding: 5,
format: (value) => {
const date = parse(value, "MM/dd/yyyy", new Date());
return format(date, "MMM d");
},
format: "%b %d",
tickValues: `every ${Number(range) > 7 ? 5 : 1} day`,
}}
theme={{
axis: {},
Expand Down

0 comments on commit f9790d0

Please sign in to comment.