# A Line chart demonstrating the crosshairs snap option

This line chart demonstrates how you can extract the Line charts dataset and index from the variables set on the canvas tag by RGraph.

Dataset:
Point:

This goes in the documents header:

    <script src="RGraph.common.core.js"></script>
    <script src="RGraph.common.dynamc.js"></script>
    <script src="RGraph.line.js"></script>

Put this where you want the chart to show up:

    <canvas id="cvs" width="600" height="400">
        [No canvas support]
    </canvas>

This is the code that generates the chart:

    <script>
        window.onload = function ()
        {
            var line = new RGraph.Line({
                id: 'cvs',
                data: [
                    [61.5,84.2,74.1,95.3],
                    [1,25,14,85],
                ],
                options: {
                    ymax: 100,
                    xmax: 365,
                    labels: ['Jan','Feb','Mar','Apr'],
                    xaxispos: 'center',
                    gutterBottom: 45,
                    hmargin: 5,
                    linewidth: 3,
                    shadow: true,
                    numxticks: 3,
                    crosshairs: true,
                    crosshairsSnap: true,
                    textAccessible: true
                }
            }).on('crosshairs', function (obj)
            {
                document.getElementById("dataset").value =  obj.canvas.__crosshairs_snap_dataset__;
                document.getElementById("point").value =  obj.canvas.__crosshairs_snap_point__;
            }).draw();
        };
    </script>