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

Get date from X Axis with Line Chart #1556

Closed
huy-jack opened this issue Jun 4, 2024 · 2 comments
Closed

Get date from X Axis with Line Chart #1556

huy-jack opened this issue Jun 4, 2024 · 2 comments

Comments

@huy-jack
Copy link

huy-jack commented Jun 4, 2024

Question
How to get the x position to get Date when clicking on the Line Chart

    this.chart.events.on('click', (event) => {
      let x = event.target.getPrivate('x'); // return undefined, there is no option "positionX" for getPrivate function, just "x"
      let dateX = this.xAxis.positionToDate(x);
    });

I also tried this but it still does not work

    cursor.events.on('click', (ev) => {
      let x = (ev.target as any).getPrivate('positionX'); // return undefined
      let dateX = this.xAxis.positionToDate(x);
    });

App info: Angular 16, Amchart 5

@martynasma
Copy link
Collaborator

The idea is to track cursor position using cursormoved event by logging it in some interval variable.

Then, when click event occurs, you can refer to that variable to know where the click occurred.

var dataItem;
cursor.events.on("cursormoved", (ev) => {
  var positionX = ev.target.getPrivate("positionX");
  var x = xAxis.toAxisPosition(positionX);
  var dataItem = xAxis.getSeriesItem(series, x);
});

chart.events.on('click', (event) => {
  console.log(dataItem);
});

Copy link

github-actions bot commented Jul 7, 2024

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

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

No branches or pull requests

2 participants