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

  Read comments...

Summary
A guide for getting the X value from a Scatter chart

[No canvas support]
X:
Y:

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:


<script>
    scatter.canvas.onmousemove = function (e)
    {
        var obj = e.target.__object__;
        var x   = obj.getXValue(e);
        var y   = obj.getYValue(e);
        
        document.getElementById("x").value = x.toFixed(1);
        document.getElementById("y").value = y.toFixed(1);
    }
</script>
Share RGraph
X

Comments