获取数组元素中的位置
Get position in array element
在JavaScript中,我无法弄清楚如何在下面的函数中使用数据对象来获取点击数据点的位置(例如third data point in the series
)。
使用 chartsNew.js,charts.js 的一个流行分支,此代码显示鼠标单击时数据点的值:
function fnMouseDownLeft(event,ctx,config,data,other){
if(other != null){
window.alert("["+ data.labels[other.v12]+", "+data.datasets[other.v11].data[other.v12] +"]");
}else{
window.alert("You click Left but not on a data");
}
}
如何显示点击元素在数据系列中的位置?
这个好像是最有前途的,但是我不明白data.datasets
、data.datasets[other]
和data.datasets[other].data[other]
之间的关系
window.alert("Position: " + data.datasets[other.v11].data[other.v3] );
这是文档:
https://github.com/FVANCOP/ChartNew.js/wiki/100_095_Mouse_Actions
https://github.com/FVANCOP/ChartNew.js/wiki/120_Template_variables#inGraphDataTmpl-annotateLabel
我的困惑:v12
(对于折线图)应该显示数据在系列中的位置(这是我想要的)但它显示该数据点的 x 轴值。
other.v12 似乎可以解决问题
alert(other.v12);
http://jsfiddle.net/wesn0xm5/1/
不知道为什么它不给你这个系列,它对我有用。
在JavaScript中,我无法弄清楚如何在下面的函数中使用数据对象来获取点击数据点的位置(例如third data point in the series
)。
使用 chartsNew.js,charts.js 的一个流行分支,此代码显示鼠标单击时数据点的值:
function fnMouseDownLeft(event,ctx,config,data,other){
if(other != null){
window.alert("["+ data.labels[other.v12]+", "+data.datasets[other.v11].data[other.v12] +"]");
}else{
window.alert("You click Left but not on a data");
}
}
如何显示点击元素在数据系列中的位置?
这个好像是最有前途的,但是我不明白data.datasets
、data.datasets[other]
和data.datasets[other].data[other]
window.alert("Position: " + data.datasets[other.v11].data[other.v3] );
这是文档:
https://github.com/FVANCOP/ChartNew.js/wiki/100_095_Mouse_Actions
https://github.com/FVANCOP/ChartNew.js/wiki/120_Template_variables#inGraphDataTmpl-annotateLabel
我的困惑:v12
(对于折线图)应该显示数据在系列中的位置(这是我想要的)但它显示该数据点的 x 轴值。
other.v12 似乎可以解决问题
alert(other.v12);
http://jsfiddle.net/wesn0xm5/1/
不知道为什么它不给你这个系列,它对我有用。