From 07bf2f998978bcec838f51cc66f70b1359c6bb5a Mon Sep 17 00:00:00 2001 From: rojonaitor Date: Tue, 7 Nov 2023 05:42:15 -0600 Subject: [PATCH 1/2] time formatting line chart --- src/components/charts/LineCharter.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/charts/LineCharter.tsx b/src/components/charts/LineCharter.tsx index 276be73d..7b5f97c6 100644 --- a/src/components/charts/LineCharter.tsx +++ b/src/components/charts/LineCharter.tsx @@ -1,4 +1,5 @@ import { Solve } from "@/interfaces/Solve"; +import formatTime from "@/lib/formatTime"; import { sort } from "fast-sort"; import { createChart } from "lightweight-charts"; import { useEffect, useRef } from "react"; @@ -17,6 +18,11 @@ const chartOptions: any = { }, }, localization: { + priceFormatter: (time: number) => { + const timeT = formatTime(time); + console.log(time); + return timeT; + }, timeFormatter: (time: number) => { return time.toString(); }, @@ -26,6 +32,9 @@ const chartOptions: any = { return time.toString(); }, }, + priceScale: { + autoScale: false, + }, }; export default function LineCharter({ @@ -46,13 +55,14 @@ export default function LineCharter({ const structuredData: any = sort( dataArray.map((i: Solve, index: number) => ({ time: index, - value: i.time / 1000, + value: i.time, })) ).asc((u: any) => u.time); const lineSeries = chart.addLineSeries({ color: cubeSelected ? "#2962FF" : "#F4D03F", }); + lineSeries.setData(structuredData); chart.autoSizeActive(); From 22a3b1e099f2d54fb32dfa9dc413fd2c6b99873d Mon Sep 17 00:00:00 2001 From: rojonaitor Date: Tue, 7 Nov 2023 06:02:24 -0600 Subject: [PATCH 2/2] fix line chart data order --- src/components/charts/LineCharter.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/charts/LineCharter.tsx b/src/components/charts/LineCharter.tsx index 7b5f97c6..a4e020c0 100644 --- a/src/components/charts/LineCharter.tsx +++ b/src/components/charts/LineCharter.tsx @@ -1,6 +1,5 @@ import { Solve } from "@/interfaces/Solve"; import formatTime from "@/lib/formatTime"; -import { sort } from "fast-sort"; import { createChart } from "lightweight-charts"; import { useEffect, useRef } from "react"; @@ -52,12 +51,14 @@ export default function LineCharter({ container.innerHTML = ""; const chart = createChart(container, chartOptions); const dataArray = cubeSelected ? data.cubeAll : data.global; - const structuredData: any = sort( - dataArray.map((i: Solve, index: number) => ({ - time: index, + const structuredData: any[] = []; + dataArray.forEach((i: Solve, index: number) => { + console.log({ time: index, value: i.time }); + structuredData.unshift({ + time: dataArray.length - index, value: i.time, - })) - ).asc((u: any) => u.time); + }); + }); const lineSeries = chart.addLineSeries({ color: cubeSelected ? "#2962FF" : "#F4D03F",