1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<?php
$values=array('Vingt' => 20, 'Cinquante' => 50, 'Trente'=>30, 'bla'=>80);
$colors=array('blue','purple');
histogram($values,1,true,200,12,10,6,300,$colors);
function histogram($values,$order, $showValue, $maxLength, $barHeight, $spacing, $gap, $tableWidth , $colors) {
$a=$values;
rsort($a);
$maxValue=$a[0];
($order==0 ? "" : ($order==1 ? asort($values) : arsort($values)));
$captions=array_keys($values);
$values=array_values($values);
$ratio=$values;
for ($i=0;$i<count($ratio);$i++) {
$ratio[$i]/=$maxValue;
}
$numberValues=count($values);
$defaultColors=array('purple','green','gold','gray','blue');
if (empty($colors)) {
($colors=$defaultColors);
}
while (count($colors)<$numberValues) {
$colors = array_merge($colors,$colors);
}
echo "<table width=$tableWidth cellpadding=0 cellspacing=0 border=0 align='left' class='bodystyle'><tbody>";
for ($i=0;$i<$numberValues;$i++){
echo "<tr height=".($barHeight+$spacing)." valign='middle'>";
echo "<td width=".($tableWidth/5-$gap)." align='right'>".$captions[$i]."</td>";
echo "<td width=$gap align='right'><IMG src='./Images/bar.png' height=100% width=1px></td>";
echo "<td width=".(4*$tableWidth/5).">";
for ($j=0; $j<($maxLength*$ratio[$i]); $j++) {
echo "<IMG src='./Images/".$colors[$i].".png' height=$barHeight width=1>";
}
echo ($showValue ? " (<I>".$values[$i]."</I>)" : "");
echo "</td></tr>";
}
echo "</tbody></table>";
}
?> |
Partager