Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $values = array();
- for($i = 0; $i < 99; $i++) {
- $values[$i] = rand(1, 10);
- }
- $values = array(count(array_keys($values, 1)),
- count(array_keys($values, 2)),
- count(array_keys($values, 3)),
- count(array_keys($values, 4)),
- count(array_keys($values, 5)),
- count(array_keys($values, 6)),
- count(array_keys($values, 7)),
- count(array_keys($values, 8)),
- count(array_keys($values, 9)),
- count(array_keys($values, 10)));
- $columns = count($values);
- $width = 1000;
- $height = 800;
- $padding = 20;
- $column_width = $width / $columns ;
- $im = imagecreate($width + 100,$height);
- $gray = imagecolorallocate ($im,0xcc,0xcc,0xcc);
- $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
- $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
- $white = imagecolorallocate ($im,0xff,0xff,0xff);
- imagefilledrectangle($im,0,0,$width + 100,$height,$white);
- $max_value = max($values);
- for($i = 0; $i < $columns; $i++) {
- $column_height = ($height / 150) * (($values[$i] / $max_value) * 100);
- $x1 = $i * $column_width + $padding;
- $y1 = $height - $column_height;
- $x2 = (($i + 1) * $column_width);
- $y2 = $height - 50;
- imagefilledrectangle($im, $x1, $y1, $x2, $y2, $gray);
- imagestring($im, 10, $width / 10 * $i + $width / 18, $height - $column_height, $values[$i], $gray_dark);
- imagestring($im, 10, $width / 10 * $i + $width / 18, $height - 20, ($i + 1), $gray_dark);
- }
- imagestring($im, 10, $width + 25, $height - 35, "Numbers", imagecolorallocate ($im,0,0,0));
- imagestring($im, 10, 25, 200, "Count", imagecolorallocate ($im,0,0,0));
- imagefilledrectangle($im, 10, $width - 25, 5, 200, imagecolorallocate ($im,0,0,0));
- imagefilledrectangle($im, 0, $height - 40, $width + 100, $height - 35, imagecolorallocate ($im,0,0,0));
- header ("Content-type: image/png");
- imagepng($im);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement