简体   繁体   中英

Amchart 5. Cursor event / Cursor X axis value

I am on amCharts5, beginner, and need some help to get the actual X value of the cursor (X axis contains dates). I found usefull examples for amcharts 4, but nothing to work with amcharts 5, I think this is a basic need though?

Or, would you recommend me HighCharts or amCharts4 instead?

Here is how far I went:

cursor.events.on("cursormoved", function(ev) {
  console.log(ev);
  console.log("x: ", ev.target.chart.xAxes.getIndex(0));
  // not working : console.log("x: ", xAxis.positionToDate(xAxis.toAxisPosition(ev.target.xPosition)));
  // not working : console.log("y: ", yAxis.positionToValue(yAxis.toAxisPosition(ev.target.yPosition)));
});

How looks my graph and cursor

1

so I finally found the proper documentation for v5... I don't know how I missed it before. But it works now!

https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/

cursor.events.on("cursormoved", function(ev) {
    var x = ev.target.getPrivate("positionX");
    var y = ev.target.getPrivate("positionY");
    var dateX = xAxis.positionToDate(xAxis.toAxisPosition(x));
    var valueY = yAxis.positionToValue(xAxis.toAxisPosition(y));
    // console.log(dateX);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM