-
Notifications
You must be signed in to change notification settings - Fork 19.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling click events on chart grid columns #2941
Comments
You activate clickable on the chart. Then you need to create a function that captures the click. The function is assigned output the options. Example is: |
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 |
For me the following works:
|
@fmal Did you happen to get a solution? |
it doesn't work, when click not on line. |
@Ovilia what does stale mean? The issue is not fixed, it is easily reproducible, lots of people experiencing it... Why is this stale? |
Have you tried with: 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: |
|
We will discuss if to put this feature in ECharts v5.0 or the next major release. I'm adding the milestone 4.5.0 for now for milestone discussion and it may also be moved to 5.0.0 if we decide to implement this in v5.0. |
One way to do this is to use an invisible graphic as a clickable element that covers the chart area. That is, add the following 'graphic' option to your chart
|
looking forward to have this feature too |
I am looking for this feature too. I am sorry, is this feature same as the following one (#9281), that, |
I got a similar problem with calendar. Although it seems to work, but gives some strange 'dates' back. Anyone an idea?
When you click the first date -> 10/10 and suddenly it jumps several months/years - depending on the selected range. |
It'd be great to have this feature. Clicking on a series isn't convenient for a large data set (the tooltip already displays the closest value), while using zRender or |
Here's my work-around (for line charts). It's not very efficient as it tries to extract the closest match in an array.
|
online demohttps://www.runoob.com/try/try.php?filename=tryecharts_event1 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts 实例</title>
<!-- 引入 echarts.js -->
<script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化ECharts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
// 处理点击事件并且弹出数据名称
myChart.on('click', function (params) {
console.log('params', params, params.name);
});
myChart.on('click', 'series', function (params) {
console.log('series', params, params.name);
});
myChart.on('click', 'series.line', function (params) {
console.log('series.line', params, params.name);
});
</script>
</body>
</html> |
@OlmoBarberis, you are a life-saver. Just so you know! |
Would be nice if the grid emitted a click event if nothing else catches it. @OlmoBarberis example works, but if you change it from bar to line then it does not work as you might expect, one should be able to click on a series line and emit an event. |
Still not working |
@zbyte64, @tamersalama, here is Demo Code - move mouse + click on lines. Chart's title is used as text output. |
Here is a more explicit example for 2024 in React using @OlmoBarberis method.
|
问题简述 (One-line summary)
Is there any way to capture click events on chart columns? My goal is to create a chart with possibility to select individual columns by clicking on them.
版本及环境 (Version & Environment)
期望结果 (Expected behaviour)
I would expect that
chart.on('click', () => { console.log('click'); });
captures click events on the entire chart. Or at least i would expect an option likegrid: { clickable: true }
.可能哪里有问题 (What went wrong)
chart.on('click', () => { console.log('click'); });
registers event only on chart components such as bars etc.ECharts配置项 (ECharts option)
The text was updated successfully, but these errors were encountered: