Hi all
i had written code for displaying graph.but it showing error like this:
Fatal error: Call to undefined function imagecreate() in /var/www/graph.php on line 27
what i have to do for get graph properly.
My code is: -
<?php
-
# ------- The graph values in the form of associative array
-
$values=array(
-
"Jan" => 110,
-
"Feb" => 130,
-
"Mar" => 215,
-
"Apr" => 81,
-
"May" => 310,
-
"Jun" => 110,
-
"Jul" => 190,
-
"Aug" => 175,
-
"Sep" => 390,
-
"Oct" => 286,
-
"Nov" => 150,
-
"Dec" => 196
-
);
-
-
-
$img_width=450;
-
$img_height=300;
-
$margins=20;
-
-
-
# ---- Find the size of graph by substracting the size of borders
-
$graph_width=$img_width - $margins * 2;
-
$graph_height=$img_height - $margins * 2;
-
$img=imagecreate($img_width,$img_height);
-
-
-
$bar_width=20;
-
$total_bars=count($values);
-
$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
-
-
-
# ------- Define Colors ----------------
-
$bar_color=imagecolorallocate($img,0,64,128);
-
$background_color=imagecolorallocate($img,43,43,43);
-
$border_color=imagecolorallocate($img,200,200,200);
-
$line_color=imagecolorallocate($img,220,220,220);
-
-
# ------ Create the border around the graph ------
-
-
imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
-
imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);
-
-
-
# ------- Max value is required to adjust the scale -------
-
$max_value=max($values);
-
$ratio= $graph_height/$max_value;
-
-
-
# -------- Create scale and draw horizontal lines --------
-
$horizontal_lines=20;
-
$horizontal_gap=$graph_height/$horizontal_lines;
-
-
for($i=1;$i<=$horizontal_lines;$i++){
-
$y=$img_height - $margins - $horizontal_gap * $i ;
-
imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
-
$v=intval($horizontal_gap * $i /$ratio);
-
imagestring($img,0,5,$y-5,$v,$bar_color);
-
-
}
-
-
-
# ----------- Draw the bars here ------
-
for($i=0;$i< $total_bars; $i++){
-
# ------ Extract key and value pair from the current pointer position
-
list($key,$value)=each($values);
-
$x1= $margins + $gap + $i * ($gap+$bar_width) ;
-
$x2= $x1 + $bar_width;
-
$y1=$margins +$graph_height- intval($value * $ratio) ;
-
$y2=$img_height-$margins;
-
imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);
-
imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);
-
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
-
}
-
header("Content-type:image/png");
-
imagepng($img);
-
-
?>
-
-
2 1981
thank you markus.
Now problem is solved.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Randell D. |
last post by:
Folks,
I feel like pulling my hair out - I tried unsuccessfully over the past few
days to install ImagMagick but because of version conflicts and missing
libraries I had to give up. I originally...
|
by: obi wan kenobi |
last post by:
i've used the Amazon PHP api for several months now to pull amazon data into
my affiliate site - but recently i'm starting to get "call to undefined
function" errors
" Fatal error: Call to...
|
by: xcomm |
last post by:
I tried to create some images with php and gd and get always
Call to undefined function imagejpeg()
or
Call to undefined function imagepng()
PHP was build with --with-gd --with-zlib but I...
|
by: Musashi |
last post by:
I'm trying to access a Cloudscape/Derby database
via PHP and am using the IBM DB2 Lite client
which I have installed.
As soon as I call db2_connect(...) in the
php code, I get a db2_connect...
|
by: Cruella DeVille |
last post by:
I'm writing a class to handle reading/writing from/to files like this
(shortened)
lass FileIO{
private $filename;
private $mode;
private $filePointer;
private $dictionary;
public function...
|
by: McHenry |
last post by:
I am trying to use curl however am not having any success with a CLI script.
Fatal error: Call to undefined function: curl_init() in
C:\PHP4\cli\processweb.php on line 65
Windows XP
PHP...
|
by: java |
last post by:
Hey there,
I just removed an elderly PHP4-Installation from my Windows-Box and
installed PHP 5.2.1. I used the PHP4-Module as local batchfile-
interpreter by
E:\ersDHCP>php ./extractLog.php
...
|
by: sanjeevvs |
last post by:
Call to undefined function: mysqli_connect() ,
i m using php5 with phpmyadmin.
i am comfortabley working with mysqli in localhost.but when i launch on web it is showing above error.
can...
|
by: Subash Biswas |
last post by:
I keep getting Call to undefined function socket_create();
(Win XPpro on domain)
IIS 6.0
PHP 5.2.5
have all extensions loaded; (and also tried enabling line
extension=php_sockets.dll in php.ini)...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |