The displayed value of the diagram JS y The axes on the mouse in the diagram relative to the X axis

In a JS chart, my chart only shows the value when my mouse moves around the chart. I want to display several chart values โ€‹โ€‹when my mouse moves around any point on the chart.

This value is for the Y axis relative to the position of the X axis of my mouse (obviously)

<!doctype html>
<html>

<head>
    <title>Line Chart</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.6/Chart.bundle.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
    <style>
    canvas{
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
    }
    </style>
</head>

<body>
    <div style="width:90%;">
        <canvas id="canvas"></canvas>
    </div>
    <br>
    <br>
    <script>

        var randomColorFactor = function() {
            return Math.round(Math.random() * 255);
        };
    var randomColor = function(opacity) {
        return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
    };

    var config = {
        type: 'line',
        data: {
            labels: [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3],
            datasets: [{
                label: "My First dataset",
                data: [12,13,14,15,21,16,15,25,16,12,15,23,16,12,13,14,15,21,16,15,25,16,12,15,23,16,12,13,14,15,21,16,15,25,16,12,15,23,16,12,13,14,15,21,16,15,25,16,12,15,23,16],
                fill: false,
                borderDash: [1, 1],
            }]
        },
        options: {
            responsive: true,
            title:{
                display:true,
                text:'Chart.js Line Chart'
            },
            tooltips: {
                mode: 'label',

            },
            hover: {
                mode: 'dataset'
            },
            scales: {
                xAxes: [{
                    display: true,
                    scaleLabel: {
                        show: true,
                        labelString: 'Month'
                    }
                }],
                yAxes: [{
                    display: true,
                    scaleLabel: {
                        show: true,
                        labelString: 'Value'
                    },
                    ticks: {
                        suggestedMin: -10,
                        suggestedMax: 25,
                    }
                }]
            }
        }
    };

    $.each(config.data.datasets, function(i, dataset) {
    });

    window.onload = function() {
        var ctx = document.getElementById("canvas").getContext("2d");
        window.myLine = new Chart(ctx, config);
    };


       </script>

the chart i get looks My schedule

I want to This one

Thanks in advance Abhishek

+4
source share

All Articles