1

In JavaScript, I am unable to figure out how to use the data object in the function below to get the position of the clicked-on data point (e.g. third data point in the series).

Using chartsNew.js, a popular fork of charts.js, this code shows the value of the datapoint at the mouse click:

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");
    }
}

How do I display the clicked element's position in the data series?

jsFiddle Example

This seems the most promising but I don't understand the relationship between data.datasets, data.datasets[other] and data.datasets[other].data[other]

window.alert("Position: " + data.datasets[other.v11].data[other.v3] );

Here is documentation:

https://github.com/FVANCOP/ChartNew.js/wiki/100_095_Mouse_Actions

https://github.com/FVANCOP/ChartNew.js/wiki/120_Template_variables#inGraphDataTmpl-annotateLabel

My confusion: v12 (for a line chart) should display the position of data in the series (which is what I want) but instead it displays the x-axis value for that datapoint.

halfer
  • 19,824
  • 17
  • 99
  • 186
crashwap
  • 2,846
  • 3
  • 28
  • 62

1 Answers1

1

other.v12 seems to do the trick

alert(other.v12);

http://jsfiddle.net/wesn0xm5/1/

Not sure why it's not giving you the series, it does for me.

Serhiy
  • 2,505
  • 3
  • 33
  • 49
  • The *one* variation I didn't try --- and (looking at it now) an obvious one, too. Thanks for the help. *The solution is often so easy... in hindsight...* – crashwap Dec 03 '15 at 00:51
  • Glad I could help, I often fall into the same pitfall. It's like proofreading your own essay and missing the same typos and grammar mistakes over and over. – Serhiy Dec 03 '15 at 00:54