简体   繁体   English

如何在任意图表中捕获 x 轴和 y 轴值

[英]how to capture x axis and y-axis value in anychart

I want to capture the x-axis and y-axis values when I click on axes in the console I want to show the values when I click on axes.我想在控制台中单击坐标轴时捕获 x 轴和 y 轴值 我想在单击坐标轴时显示这些值。

example this way :这样的例子:


chart.listen("click",function(){
chart.xAxis("{%value}");
console.log(xAxis.value(0));
});

It's not showing any value in the console I just want to get value when I click on xAxis or yAxis.它没有在控制台中显示任何值,我只想在单击 xAxis 或 yAxis 时获取值。

You can setup a click handler for individual labels, eg:您可以为单个标签设置click处理程序,例如:

const xAxis = chart.xAxis();
xAxis.labels().listen('click', function (e) {
    const labelIndex = e.labelIndex;
    const label = this.getLabel(labelIndex);
    const value = xAxis.scale().ticks().get()[labelIndex];
    console.log(value);
});

You can see it in action in this playground (click on any xAxis label and its value will be logged to the console)你可以看到它的行动在这个操场(点击任何x轴标签,其价值将被记录到控制台)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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