How to get the X/Y value from a Scatter chart

Share RGraph:  

A guide for getting the X/Y value from a Scatter chart

[No canvas support]

The Line chart has no concept of an X axis scale. The values that you supply are simply spaced equally across the chart. The Scatter chart on the other hand does have an X axis scale, so you can have an uneven distribution of elements across the chart if you so wished.

Because the X axis is scaled this means that you can get the relevant X value from a click or mousemove event. You can also get the relevant Y value so you then have an (X,Y) coordinate pair. The code to achieve this is as follows. It uses the RGraph relacement for the onmousemove event but this is not a requirement:

    scatter.canvas.onmousemove = function (e)
        var obj =;
        var x   = obj.getXValue(e);
        var y   = obj.getYValue(e);
        document.getElementById("x").value = x.toFixed(1);
        document.getElementById("y").value = y.toFixed(1);


© Copyright Richard Heyes 2008-2017