File "chart03.php"

Full Path: /home/analogde/www/videos/Json/chart03.php
File size: 1.83 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
        const tab1 = [0, 6, 37, 46, 57, 81, 98];

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

        // Générer des labels pour chaque point de données
        //const labels = tab1.map((_, index) => `Point ${index + 1}`);
       
        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,
                        borderColor: 'rgba(75, 192, 192, 1)',
                        borderWidth: 1,
                        fill: false
                    },
                    {
                        label: 'Deuxième courbe',
                        data: tab2,
                        borderColor: 'rgba(255, 99, 132, 1)',
                        borderWidth: 1,
                        fill: false
                    }
                ]
            },
            options: {
                scales: {
                    x: {
                        beginAtZero: true
                    },
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });
    </script>
</body>
</html>