What are the best practices for determining the width of bars in a graphical representation of poll results in PHP?

When determining the width of bars in a graphical representation of poll results in PHP, it is important to calculate the width of each bar based on the percentage of votes it represents. This ensures that the bars are proportional to the data they are representing. To achieve this, you can calculate the percentage of each option's votes relative to the total number of votes, and then use this percentage to determine the width of each bar.

// Sample data representing poll results
$poll_results = [
    'Option A' => 25,
    'Option B' => 40,
    'Option C' => 35
];

// Calculate total number of votes
$total_votes = array_sum($poll_results);

// Loop through each option to calculate percentage and determine bar width
foreach ($poll_results as $option => $votes) {
    $percentage = ($votes / $total_votes) * 100;
    $bar_width = $percentage * 2; // Adjust multiplier for desired width
    echo $option . ': ' . $bar_width . 'px <br>';
}