Нужно построить график посещаемости чего либо.
Тип графика - столбцы.
Т.е. X,Y координаты.
Самое важное что бы была возможность указывать не максимальное значение столбца как например на Google Сharts, а прерывать эту линию.
Надеюсь понятно объяснил =)
Насоветуйте что нибудь =)
Страница 1 из 1
Графики на PHP
#2
Отправлено 26 Январь 2010 - 14:38
Если кому интересно реализовал так :
<?php
require_once("inc/sql.inc.php");
function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1) {
if ($thick == 1) {
return imageline($image, $x1, $y1, $x2, $y2, $color);
}
$t = $thick / 2 - 0.5;
if ($x1 == $x2 || $y1 == $y2) {
return imagefilledrectangle($image,
round(min($x1, $x2) - $t),
round(min($y1, $y2) - $t),
round(max($x1, $x2) + $t),
round(max($y1, $y2) + $t), $color);
}
$k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
$a = $t / sqrt(1 + pow($k, 2));
$points = array(
round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a),
round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a),
round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a),
round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a),
);
imagefilledpolygon($image, $points, 4, $color);
return imagepolygon($image, $points, 4, $color);
}
$start = "";
$end = 0;
// header("Content-type: image/png");
$img = ImageCreateFromPng("charttmp.png");
$color = ImageColorAllocate($img, 0, 255, 0);
/* $i=0;
while($i!=17) {
ImageDashedLine($img, 60+$i*19, 293, 60+$i*19, 58, $color);
$i++;
}
*/
for($i=0;$i<24;$i++) {
$q = sprintf("SELECT * FROM online_log WHERE f_uid='".$_GET['f_uid']."' AND datetime LIKE '%%2009-11-23 %02d%%'", $i);
$sql = dosql($q);
for($j=0;$j<count($sql);$j++) {
$time = $sql[$j]['datetime'];
$time = substr($time, strpos($time, ':', 2)+1, 2);
if($start == "") {
$start = $time;
$end = $time;
continue;
}
if(($time - $end) <= 6) {
$end = $time;
continue;
} else {
ImageLineThick($img, 51+$i*19, 293-$start*4, 51+$i*19, 293-$end*4, $color, 14);
// echo "2009-11-21 ".$i.":".$start." - 2009-11-21 ".$i.":".$end."<br>\n";
$start = $time;
$end = $time;
}
}
if ($start != "") {
$end = (59-$end > 6) ? $end : 58;
ImageLineThick($img, 51+$i*19, 293-$start*4, 51+$i*19, 293-$end*4, $color, 14);
// echo "2009-11-21 ".$i.":".$start." - 2009-11-21 ".$i.":".$end."<br>\n";
$start = "";
$end = 0;
}
}
ImagePng($img, 'tmp/chart'.$_GET['f_uid'].'.png');
ImageDestroy($img);
echo "<img src=tmp/chart".$_GET['f_uid'].".png>";
?>
Поделиться темой:
Страница 1 из 1

Помощь























