Advertisement
Guest User

chart

a guest
Aug 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2.     $values = array();
  3.    
  4.     for($i = 0; $i < 99; $i++) {
  5.         $values[$i] = rand(1, 10);
  6.     }
  7.    
  8.     $values = array(count(array_keys($values, 1)),
  9.                     count(array_keys($values, 2)),
  10.                     count(array_keys($values, 3)),
  11.                     count(array_keys($values, 4)),
  12.                     count(array_keys($values, 5)),
  13.                     count(array_keys($values, 6)),
  14.                     count(array_keys($values, 7)),
  15.                     count(array_keys($values, 8)),
  16.                     count(array_keys($values, 9)),
  17.                     count(array_keys($values, 10)));
  18.    
  19.     $columns  = count($values);
  20.  
  21.     $width = 1000;
  22.     $height = 800;
  23.  
  24.     $padding = 20;
  25.  
  26.     $column_width = $width / $columns ;
  27.  
  28.     $im = imagecreate($width + 100,$height);
  29.     $gray = imagecolorallocate ($im,0xcc,0xcc,0xcc);
  30.     $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
  31.     $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
  32.     $white = imagecolorallocate ($im,0xff,0xff,0xff);
  33.  
  34.     imagefilledrectangle($im,0,0,$width + 100,$height,$white);
  35.  
  36.     $max_value = max($values);
  37.  
  38.     for($i = 0; $i < $columns; $i++) {
  39.         $column_height = ($height / 150) * (($values[$i] / $max_value) * 100);
  40.        
  41.         $x1 = $i * $column_width + $padding;
  42.         $y1 = $height - $column_height;
  43.         $x2 = (($i + 1) * $column_width);
  44.         $y2 = $height - 50;
  45.        
  46.         imagefilledrectangle($im, $x1, $y1, $x2, $y2, $gray);
  47.         imagestring($im, 10, $width / 10 * $i + $width / 18, $height - $column_height, $values[$i], $gray_dark);
  48.         imagestring($im, 10, $width / 10 * $i + $width / 18, $height - 20, ($i + 1), $gray_dark);
  49.     }
  50.    
  51.     imagestring($im, 10, $width + 25, $height - 35, "Numbers", imagecolorallocate ($im,0,0,0));
  52.     imagestring($im, 10, 25, 200, "Count", imagecolorallocate ($im,0,0,0));
  53.     imagefilledrectangle($im, 10, $width - 25, 5, 200, imagecolorallocate ($im,0,0,0));
  54.     imagefilledrectangle($im, 0, $height - 40, $width + 100, $height - 35, imagecolorallocate ($im,0,0,0));
  55.  
  56.     header ("Content-type: image/png");
  57.     imagepng($im);
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement