0

Lets say I already build a component with google chart in ReactJS, and I want to make the Legend to show/hide data by using a js script shown here.

How and where should I put this piece of code to react with my chart?

My component look something like this: PlayerCountStat

//Skipping all the imports and useEffect code...
  return (
    <Chart
      chartType="LineChart"
      width="100%"
      height="400px"
      data={dateData}
      options={options}
      chartPackages={["corechart", "controls"]}
      controls={[
        {
          controlType: "ChartRangeFilter",
          options: {
            filterColumnIndex: 0,
            ui: {
              chartType: "LineChart",
              chartOptions: {
                chartArea: { width: "90%", height: "50%" },
                hAxis: { baselineColor: "none" },
              },
            },
          },
          controlPosition: "bottom",
          controlWrapperParams: {
            state: {
              range: {
                start: {startFilterDate},
                end: {endFilterDate}
              },
            },
          },
        },
      ]}
    />
  );
}

export default PlayerCountStat

And the Routing is like this

function App() {
  return (
    <BrowserRouter>
        <Route path="/PlayerCountStat">
          <Navbar/>
          <Page content={PlayerCountStat}/>
        </Route>
      </Switch>
    </BrowserRouter>
  );
}

export default App;

0

1 Answer 1

2

Assuming you're using React Google Charts, there is a prop called chartEvents

<Chart 
   chartType="LineChart"
   width="100%"
   height="400px"
   data={data}
   options={options}
   chartEvents={[
     {
       eventName: 'select' // Change this to applicable event,
       callback: ({ chartWrapper }) => {
          // Add your logic
       }
     }
   ]}
/>

I found this codepen that might be what you're looking to accomplish: https://codesandbox.io/s/d9drj?file=/index.js

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, its much better than what I was trying to do and achive the same results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.