Skip to content
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

chart area mousemove #393

Open
cscrum opened this issue Apr 3, 2023 · 1 comment
Open

chart area mousemove #393

cscrum opened this issue Apr 3, 2023 · 1 comment

Comments

@cscrum
Copy link

cscrum commented Apr 3, 2023

I found the mouse move event, but it only works if you are touching a data series. I have a chart with 5 lines, and I'd like to capture a mouse move across the chart much like the tooltip or the axis lines that show my current position. Is there a way to access the graph position when moving anywhere within the axes or to tap into the grid lines position?

@xieziyu
Copy link
Owner

xieziyu commented Apr 4, 2023

Hi @cscrum ,

Indeed, the MouseEvent provided by ECharts cannot meet your needs, so there is no directly available @Output event in ngx-echarts. Based on your description, you may need to utilize the underlying library that ECharts relies on for rendering: ZRender. Here's a reference example for your consideration:

<div echarts (chartInit)="onChartInit($event)" [options]="options" class="chart"></div>
import { ECharts, zrender } from 'echarts';

export class AppComponent implements onDestroy {
  chartRender?: zrender.ZRenderType

  //... other options ...

  onChartInit(chart: ECharts) {
    this.chartRender = chart.getZr();
    // add event listener
    this.chartRender.on('mousemove', (params) => {
      // TODO: params should be useful
    });
  }

  ngOnDestroy() {
    // remove event listener
    this.chartRender?.off('mousemove');
  }
}

And the official example provided by ECharts: demo

I hope it is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants