//array of values $test = array (35070, 24440, 4730, 35700, 29380, 22860, 28870, 22730, 26270); //generate chart echo chart($test, 400); //function function chart($array, $size){ $max = max($array); $ratio = $size / $max; $out = ''; foreach($array as $element){ $width = ceil($element * $ratio); $out .= "<div class=\"chart\" style=\"width: ".$width."px;\">$element</div>\n"; } return $out; }