Hi all,
I have got a problem with plotting bar graph using GD. I am learning GD now.
I have written the code for basic bar graph with one bar. What I need is, scale on Y-axis i.e. divisions on y-axis like 500,1000,1500 upto value which I have mentioned in $max variable which in my case is 4000.
Here is the code - <?php
-
-
header("Content-type: image/jpeg");
-
-
$data = '1000';
-
$max = '4000';
-
-
$height = 255;
-
$width = 320;
-
-
$im = imagecreate($width,$height); // width , height px
-
-
$white = imagecolorallocate($im,255,255,255);
-
$black = imagecolorallocate($im,0,0,0);
-
$red = imagecolorallocate($im,255,0,0);
-
-
imageline($im, 10, 5, 10, 230, $black);
-
imageline($im, 10, 230, 300, 230, $black);
-
-
$x = 15;
-
$y = 230;
-
$x_width = 20;
-
$y_ht = 0;
-
-
$y_ht = ($data/$max)* $height;
-
-
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
-
imagestring( $im,2,$x-1,$y+10,$data,$black);
-
-
$x += ($x_width+20);
-
-
imagejpeg($im);
-
-
?>
Please give me some idea regarding this.
With regards
6 2593 pbmods 5,821
Recognized Expert Expert
Heya, gubbachchi.
Could you be a little more specific?
What is your code supposed to do that it's not doing?
What is your code *not* supposed to do that it is doing?
Heya, gubbachchi.
Could you be a little more specific?
What is your code supposed to do that it's not doing?
What is your code *not* supposed to do that it is doing?
Hi,
Thanks for your reply.
Actually what I need is, I need to mark divisions on X-axis and y-axis.
That is on x-axis i need divisions of 10,20,30,40 and on y-axis 500,1000,1500,2 000,2500 to be marked on horizontal and vertical axis to be marked. I hope you got the point now. Can you please help me out.
With regards
Take a look here:
http://www.phpclasses. org/browse/file/6059.html
This is what I found when I had to implement bargraphs in my application. I use it pretty much like it is with some minor modifications to suit my needs. Even if you do not use this and rather make your own, the code is not difficult to understand and is a great "learn by example", which is how I always learn something new in programming.
dlite922 1,584
Recognized Expert Top Contributor
Hi all,
I have got a problem with plotting bar graph using GD. I am learning GD now.
I have written the code for basic bar graph with one bar. What I need is, scale on Y-axis i.e. divisions on y-axis like 500,1000,1500 upto value which I have mentioned in $max variable which in my case is 4000.
Here is the code - <?php
-
-
header("Content-type: image/jpeg");
-
-
$data = '1000';
-
$max = '4000';
-
-
$height = 255;
-
$width = 320;
-
-
$im = imagecreate($width,$height); // width , height px
-
-
$white = imagecolorallocate($im,255,255,255);
-
$black = imagecolorallocate($im,0,0,0);
-
$red = imagecolorallocate($im,255,0,0);
-
-
imageline($im, 10, 5, 10, 230, $black);
-
imageline($im, 10, 230, 300, 230, $black);
-
-
$x = 15;
-
$y = 230;
-
$x_width = 20;
-
$y_ht = 0;
-
-
$y_ht = ($data/$max)* $height;
-
-
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
-
imagestring( $im,2,$x-1,$y+10,$data,$black);
-
-
$x += ($x_width+20);
-
-
imagejpeg($im);
-
-
?>
Please give me some idea regarding this.
With regards
Why not do this with HTML and CSS.
Do a forloop for each bar, and the heigh of each bar is the style.height = $height.
Please note that's not suppose to be actual code*
Pretty nifty stuff if you use AJAX!
-Dan
Thanks dlite922 for your reply.
But I need to do this using GD only, this is requirement of the project.
With regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: TheDD |
last post by:
Hi all,
i have a question:
is there any librairy for drawing graphs with PHP? Not graphs like
histogram or alike, but like a set of shapes linked together in a certain
way (like a flow chart or call graph).
I have found a script to handle the graph in memory but i can already do
that, my problem is to draw it (it an optimal way, and without crossing
|
by: SS KANAGAL |
last post by:
Hello,
I am drawing a bar graph in an aspx page using
System.Drawing namespace .
Now I want to provide drill down facility for the graph
i.e. on click of a bar in the graph it should get me yet
another graph with different data populated in that graph.
I want to know how to provide href for each bar in the
graph in the code behind.
|
by: SS KANAGAL |
last post by:
Hello,
I am drawing a bar graph in an aspx page using
System.Drawing namespace .
Now I want to provide drill down facility for the graph
i.e. on click of a bar in the graph it should get me yet
another graph with different data populated in that graph.
I want to know how to provide href for each bar in the
graph in the code behind.
|
by: Senne Vaeyens |
last post by:
Hi,
I'm writing an app that will show a scrolling transparent graph and I'm
ancountering some problems, explained in the following code:
(a VS project explaining the problem(s) can be downloaded at
http://www.icat.be/problems.zip )
The code is executed on a timer.tick event:
// Draw Using Double Buffering, this works perfectly if the monitor
|
by: Anupam Soni CMC Ltd. |
last post by:
Hi All,
I have drawn Pie/Bar using some values now I want to capture any segment of
Pie or Block of Bar graph if user click on that area. Plz suggest how can I
do that .
I have to show trendline of that particular segment in new form .
Plz help me ....
| |
by: DBC User |
last post by:
Hi Sharpies,
This is a very basic question. I am using .Net IDE 2003 and
System.Drawing.dll (1.1.4322). I wrote a simple program like this
(ommitting the commons)
using System.Drawing;
..
..
|
by: anthonyroche |
last post by:
Does anyone know of a product that allows a user to draw a line on a
chart?
eg A historical stock tracker would have a line graph of say Aug 03 to
Dec 03, which is a line graph representing a stock over that period. I
want to give the user the functionality to draw a line on the graph
(Straight line) representing what they consider the trend. All web
based..
Any information would be of great help, I have already the component
that does...
|
by: Bad_Kid |
last post by:
(c++) I have to present a wave which is stored in a file (int numbers, I
know sample's freq) on some kind of graph. I've never been using drawing in
c++.
Any suggestions, the easiest way to do that?
thanx...
|
by: RichMo |
last post by:
Hi,
I'm new to C++ and i can't seem to find a tutorial on the net for this
one.
I have a dialog based MFC app running that reads sensors using a USB
interface device.
At the moment the varying data just moves a progress bar up and down.
I'm looking for a way to display this sensor data as a graph on the
|
by: davetelling |
last post by:
I am not a programmer, I'm an engineer trying to make an interface to a
product I'm designing. I have used C# to make a form that interrogates the
unit via the serial port and receives the data. I want to be able to draw
lines in a picturebox based upon certain data points I have received. I
dragged a picturebox from the toolbar onto my form, but after having gone
through the help files, looking online and trying a variety of things, I...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |