What are the best practices for visually representing CSV data using PHP, especially when combining data from multiple sensors?

When visually representing CSV data from multiple sensors in PHP, it is best to use a charting library like Chart.js or Google Charts to create interactive and visually appealing graphs. These libraries allow you to easily plot data points from different sensors on the same chart, making it easier to compare and analyze the data.

<?php
// Sample code using Chart.js to create a line chart from CSV data

// Load CSV data into an array
$data = array_map('str_getcsv', file('data.csv'));

// Extract data for each sensor
$sensor1 = array_column($data, 1);
$sensor2 = array_column($data, 2);

// Create labels for the chart
$labels = array_column($data, 0);

// Create a JSON object with data for the chart
$chart_data = [
    'labels' => $labels,
    'datasets' => [
        [
            'label' => 'Sensor 1',
            'data' => $sensor1,
            'backgroundColor' => 'rgba(255, 99, 132, 0.2)',
            'borderColor' => 'rgba(255, 99, 132, 1)',
            'borderWidth' => 1
        ],
        [
            'label' => 'Sensor 2',
            'data' => $sensor2,
            'backgroundColor' => 'rgba(54, 162, 235, 0.2)',
            'borderColor' => 'rgba(54, 162, 235, 1)',
            'borderWidth' => 1
        ]
    ]
];

// Encode the data as JSON
$chart_data_json = json_encode($chart_data);
?>

<!DOCTYPE html>
<html>
<head>
    <title>CSV Data Visualization</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
    <canvas id="myChart"></canvas>
    <script>
        var ctx = document.getElementById('myChart').getContext('2d');
        var myChart = new Chart(ctx, {
            type: 'line',
            data: <?php echo $chart_data_json; ?>,
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: true
                        }
                    }]
                }
            }
        });
    </script>
</body>
</html>