File "chart0004.php"

Full Path: /home/analogde/www/DOSSIER/Json/chart0004.php
File size: 2.37 KB
MIME-type: text/html
Charset: utf-8

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Graphique avec Chart.js</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
    <h1>Graphique des valeurs</h1>
    <canvas id="myChart" width="400" height="200"></canvas>
    <script>
        // Premier tableau de valeurs pour l'axe X
        const tab1 = [0, 6, 37, 46, 57, 81, 98];

        // Deuxième tableau de valeurs pour l'axe X
        const tab2 = [5, 10, 25, 30, 45, 60, 75];

        // Valeurs pour l'axe Y
        const labels = [1, 2, 3, 4, 5, 6];

        // Configuration du graphique
        const ctx = document.getElementById('myChart').getContext('2d');
        const myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: labels,
                datasets: [
                    {
                        label: 'Première courbe',
                        data: tab1.map((_, index) => ({ x: tab1[index], y: labels[index] })),
                        borderColor: 'rgba(75, 192, 192, 1)',
                        borderWidth: 1,
                        fill: false,
                        showLine: true // Pour ne pas afficher la ligne entre les points
                    },
                    {
                        label: 'Deuxième courbe',
                        data: tab2.map((_, index) => ({ x: tab2[index], y: labels[index] })),
                        borderColor: 'rgba(255, 99, 132, 1)',
                        borderWidth: 1,
                        fill: false,
                        showLine: true // Pour ne pas afficher la ligne entre les points
                    }
                ]
            },
            options: {
                scales: {
                    x: {
                        beginAtZero: true,
                        type: 'linear', // Pour traiter les valeurs de l'axe X comme des nombres
                        position: 'bottom'
                    },
                    y: {
                        beginAtZero: true,
                        type: 'linear', // Pour traiter les valeurs de l'axe Y comme des nombres
                        position: 'left'
                    }
                }
            }
        });
    </script>
</body>
</html>