获取股票图表十字准线yAxis价格点击



我有一个股票图表,我想获得在yAxis标签中显示的值,十字准星在单击绘图时创建。本质上,我想知道当我点击鼠标的当前位置时,y轴上的价格是多少。假设十字准线yAxis标签显示20,当我点击时,我想把这个20放入一个变量中。那么我怎样才能得到准星的y轴值?由于

const yAxis = plot.yAxis();
plot.listen('click', function (e) {
console.log(e)
//this will get the first label on the y Axis, this is 12
//I dont want the yAxis of the chart labels, I want the crosshair yAxis label
const value = yAxis.scale().ticks().get()[0];
console.log(value)
//prints  12
var value = chart.crosshair().yLabel()
//I dont know what to query to get the "value" of the label
console.log(value)

});

可以获取yAxis标签值

可以通过访问情节的准星对象来实现。

//Create variable for label value
let yAxisLabelValue = 0;
//Handling click event
plot.listen("click", (e) => {
let label = plot.crosshair().yLabel();
let labelValue = label.text();

//Asigning current value to a variable
yAxisLabelValue = labelValue;
});

请随意在操场上尝试如何与十字准星进行交互。

最新更新