所以我想这比 PHP 更像是一个数学问题,但我不知道它还能去哪里。所以我有一个电视节目网站,显示每个用户的收视率分布。在这里可以看到两个例子http://broadcasted.tv/user/2/albertmarch/和这里http://broadcasted.tv/user/21/freshprincelive/。这是我目前用来计算每个条形的公式:
$division = $scores[$i][1] / $countvotestotal;
//we divide the number of scores for each score (1 to 10) by the total number of score
$percentage = $division * 100;
$pixels = 180;
//max number of pixels
$pixelsactual = ($percentage / 100) * $pixels;
$addthat = $percentage * 3.4;
//add some pixels to give more relief to the charts (otherwise, with many ratings, you end having bars between 10px and 20px)
$finalpixels = $pixelsactual + $addthat;
if ($finalpixels > 130) {
$finalpixels = 130;
}
//and this is a fix that I use, basically, if there is only one rating the biggest bar is gonna be huge (especially because of the $addthat var which add some px with a ratio to the final pixels value)
问题是有些图表看起来很糟糕(就像第一个配置文件一样)或者不同的值具有相同的条形大小,就像那里http://broadcasted.tv/user/98/armchairtv/
任何建议将不胜感激。谢谢