PDA

View Full Version : سوال: نمایش نظر سنجی



student91
دوشنبه 11 اردیبهشت 1391, 09:00 صبح
سلام.
می خوام درصد های یک نظر سنجی رو بدم به یک تابع و اون برام نمودارشو رسم کنه!می تونید کمکم کنید؟

Hamid.RDN
دوشنبه 11 اردیبهشت 1391, 11:30 صبح
خوب دوست عزیز

اینم تابع و مثالش


function drawBar($percent = 0, $color= '')
{
if($color == '')
{
$color = '#'.dechex(mt_rand(0, 0xFFFFFF));
}

echo '<div style="width:'.$percent.'%; height:16px; background-color: '.$color.'; margin:10px;">'.$percent.'%</div>';
}

drawBar(20);
drawBar(83);
drawBar(10);
drawBar(91);
drawBar(56);
drawBar(49);

student91
دوشنبه 11 اردیبهشت 1391, 12:13 عصر
ممنون ولی من میخوام به صورت میله ای یعنی عمودی نمایش داده بشه!

Hamid.RDN
دوشنبه 11 اردیبهشت 1391, 13:01 عصر
اینم کد میله ای


<?php

function drawBar($percent = 0, $color= '')
{
if($color == '')
{
$color = '#'.dechex(mt_rand(0, 0xFFFFFF));
}
echo '<td valign="bottom"><div style="width:16px; height:'.$percent.'%; background-color: '.$color.'; margin:10px;">'.$percent.'%</div></td>';
}

echo '<table style="height:500px;"><tr>';
drawBar(20);
drawBar(83);
drawBar(10);
drawBar(91);
drawBar(56);
drawBar(49);
echo '</tr></table>';