From d172a30808b61e77a51c3a055d7514d26a6731de Mon Sep 17 00:00:00 2001 From: Aryan Kothari <87589047+thearyadev@users.noreply.github.com> Date: Sat, 17 Feb 2024 10:59:22 -0500 Subject: [PATCH] add button to hide all lines in line chart --- frontend/app/components/charts/lineChart.tsx | 24 ++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/charts/lineChart.tsx b/frontend/app/components/charts/lineChart.tsx index 31134f49..c40b51c6 100644 --- a/frontend/app/components/charts/lineChart.tsx +++ b/frontend/app/components/charts/lineChart.tsx @@ -2,7 +2,7 @@ import * as Highcharts from "highcharts"; import HighchartsReact from "highcharts-react-official"; -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { HeroColors } from "@/app/components/charts/heroColors"; import type { TrendLine } from "@/app/utils/serverSideProps"; import classNames from "classnames"; @@ -16,7 +16,7 @@ interface LineChartProps extends HighchartsReact.Props { const LineChart = (props: LineChartProps) => { const { data, seasons, title } = props; - const options: Highcharts.Options = { + const [options, setOptions] = useState({ title: { // @ts-ignore text: null, @@ -56,13 +56,26 @@ const LineChart = (props: LineChartProps) => { }, }, }, - }; + }) + + + const chartComponentRef = useRef(null); const [loading, setLoading] = useState(true); + const hideLines = () => { + setOptions((prevState) => { + return { + ...prevState, + series: options.series?.map((series) => ({ ...series, visible: false })) + + } + }) + + } + return (
{title}
-
{ ref={chartComponentRef} {...props} /> +
+ +