Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Utilizing Plot Events of G2 Plot in React Component #354

Answered by kagawagao
jagijan asked this question in Q&A
Discussion options

Hello folks,

Could someone provide insight on how to utilize plot events provided in G2 Plot when using g2plot-react library?
I've designed a bar chart & I would like to perform some action when user clicks a particular element (i.e. bar) in the chart.

Thank you in advance!

You must be logged in to vote

you can use chartRef to access chart plot instance, then follow g2plot events api to bind event

 const lineChartRef = useRef<Line>();
 useEffect(() => {
 if (lineChartRef.current) {
 const plot = lineChartRef.current;
 plot.on("line:click", (e) => {
 console.log(e);
 });
 }
 }, []);

demo

Replies: 1 comment

Comment options

you can use chartRef to access chart plot instance, then follow g2plot events api to bind event

 const lineChartRef = useRef<Line>();
 useEffect(() => {
 if (lineChartRef.current) {
 const plot = lineChartRef.current;
 plot.on("line:click", (e) => {
 console.log(e);
 });
 }
 }, []);

demo

You must be logged in to vote
0 replies
Answer selected by kagawagao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /