Не получается вывести график php
Нужно построить график в php, не используя библиотеки. Данные берутся с БД. Наклепал свой говнокод еле живой, но никак не могу понять, как вывести график. Прошу о помощи.
<?php
$dollar = $_GET['dollar'];
$euro = $_GET['euro'];
$pound = $_GET['pound'];
$year = $_GET['year'];
$number = $_GET['number'];
$username = "mysql";
$password = "mysql";
$dbName = "lab10";
$mysqli = new mysqli("localhost", $username, $password, $dbName);
if(mysqli_connect_errno()){
printf(nl2br("Ошибка соединения: %s\n"), mysqli_connect_error());
exit();
}
if(!$mysqli->set_charset("utf8")){
printf(nl2br("Ошибка кодировки"), $mysqli->error);
exit();
}
$fontFile = "C:\Windows\Fonts\arial.ttf";
if (($dollar == 0) && ($euro == 0) && ($pound == 0)) {
header("Content-Type: image/jpeg");
$imH = 700;
$imW = 900;
$im = ImageCreate($imW, $imH);
$bgcolor = ImageColorAllocate($im,255,255,200);
$textColor = ImageColorAllocate($im,0,0,0);
imagettftext($im, 30, 0, 350, 270, $textColor, $fontFile, "Ошибка");
imagettftext($im, 30, 0, 130, 330, $textColor, $fontFile, "По данному запросу данных нет!");
imagepng($im);
}
else{
$dollar_data = array();
$euro_data = array();
$pound_data = array();
$values = array();
$dates = array();
$query = "SELECT CDate, dollar, euro, GBP FROM tcurrency WHERE YEAR(CDate) = '$year'";
$res = $mysqli->query($query);
$row = $res->fetch_row();
$check_number = mysqli_num_rows($res);
if($result = $mysqli->query($query))
while($row = $result->fetch_array(MYSQLI_ASSOC)){
array_push($dates, $row['CDate']);
}
if ($number > $check_number)
$number = $check_number;
if($dollar)
if($result = $mysqli->query($query))
while($row = $result->fetch_array(MYSQLI_ASSOC)){
array_push($values, $row[1]);
array_push($dollar_data, $row[1]);
}
if($euro)
if($result = $mysqli->query($query))
while($row = $result->fetch_array(MYSQLI_ASSOC)){
array_push($values, $row[2]);
array_push($euro_data, $row[2]);
}
if($pound)
if($result = $mysqli->query($query))
while($row = $result->fetch_array(MYSQLI_ASSOC)){
array_push($values, $row[3]);
array_push($pound_data, $row[3]);
}
$imH = 700;
$imW = 900;
header("Content-Type: image/png");
$im = imageCreate($imW, $imH);
$bgcolor = imageColorAllocate($im, 255, 255, 200);
$black = imageColorAllocate($im, 0, 0, 0);
$color = imageColorAllocate($im, 184, 224, 191);
$color_dollar = imageColorAllocate($im, 16, 133, 55);
$color_euro = imageColorAllocate($im, 222, 252, 28);
$color_pound = imageColorAllocate($im, 88, 10, 255);
$y1 = $imH - 80;
$y2 = 80;
$x1 = 50;
$x2 = $imW - 50;
imagefilledrectangle($im, 0, 0, $imW, $imH, $bgcolor);
imagefilledrectangle($im, 50, 80, $x2, $y1, $color);
$j = 0;
while(($i + $x1) < $x2){
imagedashedline($im, $x1 + $i, $y1, $x1 + $i, $y2, $black);
imagettftext($im, 11, 90, $x1 + $i + 6, $imH - 5, $black, $fontFile, $dates[$j]);
$i += ($imW - 100) / $number;
$j++;
}
$k = 0;
$i = 0;
while(($y1 - $i) > $y2){
imagedashedline($im, $x1, $y1 - $i, $x2, $y1 - $i, $black);
imagettftext($im, 11, 0, 5, $y1 - $i + 6, $black, $fontFile, $k);
$i += 20;
$k += 20;
}
imagesetthickness($im, 4.5);
$text = "Динамика курсов валют. Год: $year";
imagettftext($im, 14, 0, 300, 50, $black, $fontFile, $text);
$dollar_label = "Dollar";
$euro_label = "Euro";
$pound_label = "Pound";
imagettftext($im, 12, 0, 700, 30, $black, $fontFile, $dollar_label);
imageline($im, 760, 25, 800, 25, $color_dollar);
imagettftext($im, 12, 0, 700, 45, $black, $fontFile, $euro_label);
imageline($im, 760, 40, 800, 40, $color_euro);
imagettftext($im, 12, 0, 700, 60, $black, $fontFile, $pound_label);
imageline($im, 760, 55, 800, 55, $color_pound);
imagepng($im);
}
?>