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 2573
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,2000,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.
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |