Pedanfer commented on issue #2941:
URL: https://github.com/apache/echarts/issues/2941#issuecomment-2322873111

   > > But when I click between two columns, I can not receive any event. I 
wish I can get the dataIndex where the blue line located. Any idea? @coretez
   > > 
![image](https://user-images.githubusercontent.com/1694541/34925970-9af9a352-f9e7-11e7-9027-f7817d241296.png)
   > 
   > Have you tried with: `const zr = chart.getZr(); zr.on('click', (params) => 
{ console.log(params); });`
   > 
   > You can take extract coordinates from params and get dataIndex with 
chart.convertFromPixel.
   > 
   > I have used it in my project and I had found an example that used getZr() 
but I can't find it again now!
   > 
   > EDIT: I have found the example: 
https://echarts.apache.org/examples/en/editor.html?c=line-pen
   
   Here an even more explicit example for 2024 in React using his method.
   
     const chartRef = useRef<EChartsInstance>();
   
   ```
     useEffect(() => {
       var zr = chartRef.current.getZr();
       zr.on("click", function (params) {
         var pointInPixel = [params.offsetX, params.offsetY];
   
         var pointInGrid = chartRef.current.convertFromPixel({ gridIndex: 0 }, 
pointInPixel);
   
         if (pointInGrid) {
           var xValue = pointInGrid[0] * 1;
           var xAxis = chartRef.current.getModel().getComponent("xAxis", 0);
           const categoryClicked = xAxis.getCategories()[xValue];
           console.log("Category clicked:", xAxis.getCategories()[xValue]);
         }
       });
     }, []);
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to