<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>New vs Old Buyers</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>

<canvas id="buyersChart" width="400" height="200"></canvas>

<script>
    const ctx = document.getElementById('buyersChart').getContext('2d');

    // Data preparation
    const newBuyers = <?php echo isset($comparison['new_buyers']) ? $comparison['new_buyers'] : 0; ?>;
    const oldBuyers = <?php echo isset($comparison['old_buyers']) ? $comparison['old_buyers'] : 0; ?>;

    const buyersChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: ['New Buyers', 'Old Buyers'],
            datasets: [{
                label: 'Number of Buyers',
                data: [newBuyers, oldBuyers],
                backgroundColor: [
                    'rgba(75, 192, 192, 0.2)',
                    'rgba(153, 102, 255, 0.2)'
                ],
                borderColor: [
                    'rgba(75, 192, 192, 1)',
                    'rgba(153, 102, 255, 1)'
                ],
                borderWidth: 1
            }]
        },
        options: {
            scales: {
                y: {
                    beginAtZero: true
                }
            }
        }
    });
</script>

</body>
</html>
