Startseite Profil ORACLE PHP VB EXCEL Links Kontakt

Top

Line (#1)

Line (#2)

Result
Datei: draw_chart.php

<?php
//*************************************************************************
// Create a line chart image                                              *
// Author: A. Nay, 30.06.2011                                             *
//*************************************************************************
// General properties and drawing functions are found in the included file
include ("chart_pref.inc");
$points = array();

// Create a new image (background is black by default)
$img = imagecreatetruecolor($x, $y);

// Make the background transparent
imagesavealpha($img, true);
$trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagefill($img, 0, 0, $trans_colour);

// Create painting colors
$bordcol = imagecolorallocate($img, 5, 5, 5);          // Borderline-/Axis-color
$pencol = imagecolorallocate($img, 255, 150, 50);      // Line color
$pntcol = imagecolorallocate($img, 127, 127, 127);     // Data point color
$linecol  = imagecolorallocate($img, 127, 127, 255);   // Data line color

// Draw borderline
draw_border($img, $x, $y, $bordcol);

// Draw y- and x-axis with linewidth 2 including axis labels
draw_axis($img, $x, $y, $border, $line2, $x_axis_label, $y_axis_label, $axis_label_size, $bordcol);

// Draw axis tics with linewidth 1 and tic labels
draw_axis_tics($img, $x, $y, $border, $x_tic_cnt, $y_tic_cnt, $ticlen, $x_minval, $x_maxval,
               $y_minval, $y_maxval, $line1, $tic_label_size, NULL, NULL, NULL, NULL, $bordcol);

// Fill the data point array with data retrieved from the ORACLE database
$conn = oci_connect('scott', 'tiger', 'orcl');
$stid = oci_parse($conn, 'SELECT YYYYMM, SSN FROM ssn_data ORDER BY 1');

oci_execute($stid);

while (($row = oci_fetch_array($stid)))
 {
  // Default call of oci_fetch_array returns associative and numeric indices (OCI_BOTH)
  $points[] = $row['YYYYMM'];  // first column (x-value)
  $points[] = $row['SSN'];     // second column (y-value)
 }

oci_free_statement($stid);
oci_close($conn);

// Count points in the array
$totalPoints = count($points)/2;

// Write the chart header
write_heading($img, ($x/2) - $border - 100, $border/2, $header_size, 
              $header_text . " based on " . strval($totalPoints) . " datapoints", $pencol);

// Draw every data point
for ($p=0; $p<$totalPoints; $p++)
{
 draw_data_point($img, $x, $y, $border, $x_minval, $x_maxval, $y_minval, $y_maxval, $points[2*$p],
                 $points[1+2*$p], $p_radius, $pntcol);
}

// Draw the data lines
for ($l=0; $l<$totalPoints-1; $l++)
{
 draw_data_line($img, $x, $y, $border, $x_minval, $x_maxval, $y_minval, $y_maxval, $points[2*$l],
                $points[1+2*$l], $points[2+2*$l], $points[3+2*$l], $linecol, $line1);
}

// Output image in the browser
header("Content-type: image/png");
imagepng($img);

// Free memory (cleanup)
imagedestroy($img);
?>

Version 1.0
04.09.2012