1. Main application scenarios

When the business requirement is to click on a line graph and send a request there needs to be a click event to trigger the request data event;

2. Here’s an example

Add a click event to a point on the Echarts line chart and print the data for the horizontal and vertical points.

01. The effect is as follows:

02. Add click events:

Echart adds click events to mychart.setoption (option) by using on method.

Mychart. on('click', function (params) {// select * from the list where the function is; let data = { x: params.name, y: params.value } console.log(data) alert(JSON.stringify(data)) });Copy the code

03. Make a broken line chart

Juejin. Cn/post / 704362…

04. And a pit

Mychart.off (“click”); mychart.off (“click”); Complete code:

myChart.off("click"); Mychart. on('click', function (params) {// select * from the list where the function is; let data = { x: params.name, y: params.value } console.log(data) alert(JSON.stringify(data)) });Copy the code