473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Use PHP to do Line Graph

Anyone have any idea on how to do a simple line graph using PHP codes?
Dec 26 '07 #1
3 2525
Markus
6,050 Expert 4TB
Try the jpgraph library.

Hope that helps.

Regards, markus.
Dec 26 '07 #2
How can i use something like this to do a line graph??? Anyone can give me any clue on that???


http://www.daniweb.com/forums/thread100930.html

<?php
include_once 'db.php';

$qt=mysql_query("select * from gd_graph1 order by sales");


header ("Content-type: image/gif");


$x_gap=40; // The gap between each point in y axis

$x_max=$x_gap*13; // Maximum width of the graph or horizontal axis
$y_max=250; // Maximum hight of the graph or vertical axis
// Above two variables will be used to create a canvas of the image//


$im = @ImageCreate ($x_max, $y_max)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 234, 234, 234);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
$graph_color = ImageColorAllocate ($im,25,25,25);

$x1=0;
$y1=0;
$first_one="yes";
while($nt=mysql_fetch_array($qt)){
//echo "$nt[month], $nt[sales]";
echo $nt['month'];
echo $nt['sales'];
$x2=$x1+$x_gap; // Shifting in X axis
$y2=$y_max-$nt[sales]; // Coordinate of Y axis
ImageString($im,2,$x2,$y2,$nt[month],$graph_color);
//Line above is to print month names on the graph
if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0
imageline ($im,$x1, $y1,$x2,$y2,$text_color); // Drawing the line between two points
}
$x1=$x2; // Storing the value for next draw
$y1=$y2;
$first_one="no"; // Now flag is set to allow the drawing
}

ImageJPEG ($im);

?>
Dec 27 '07 #3
spudse
11
Jpgraph is indeed created just to do this. The script you pasted is a Jpgraph script also.

Jpgraph is a sort of script/library that uses GD library (needs to be installed in php) to create graphs. It comes with a massive load of examples, which you can alter to create into something you like.
Jan 7 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lisa Tracy | last post by:
I have a line graph in Crystal Reports 8.5. There are dates along the x-axis and scores along the y-axis. I have 2 data series, so there are 2 lines graphed. My problem occurs when one of the...
2
by: Tim Byrne | last post by:
I have wrote a program that lets the user choose stock data types that they wish to analyse. Their choices are then read in from a database. I want to know how to then graph the data using a line...
7
by: news | last post by:
This may be a stupid question, but if I don't ask I'll never know ;) Ok, here it goes.... I am writing an application that renders an image in one picturebox and a graph in another. The image...
1
by: Roger Oshaug | last post by:
Access 2003 I have a simple line graph with one line and I need an extra horizontal line in that graph. I want something similar to this, (without the vertical line): ...
3
by: Bob Greschke | last post by:
I've resorted to actually drawing all of the characters of the alphabet on a graph to avoid having to drag around font files. It's mostly just uppercase characters, so it's not too bad. But I...
1
by: Sharon | last post by:
(Frustratingly), after unsuccessfully trying to use a picturebox control to paint a line graph based on serial communications with a remote device, it seems picturebox controls just won't work for...
2
by: balakrishnan.dinesh | last post by:
Hi Frnds, I want to know about, how to use color in canvas in javascript. Bcoz im using canvas in javascript for plotting line graph, I have plotted the linegraph, now i need to differentiate...
2
blazedaces
by: blazedaces | last post by:
Hey, I have an application that draws a polyline with Graphics': g.drawPolyline(getXPoints(),getYPoints(),nPoints); It's drawn onto a background image and so the background image is so many...
3
by: goldreads | last post by:
Hey guys, I've been putting together a line graph in Image_Graph. And I can't seem to find an answer to change the layout of few things. Here is my graph: http://www.goldreads.com/test.png ...
4
by: networkmancer | last post by:
Written in Turbo C++ so dont tell me its very messy because I know it is and this is an assignment that we must stick in to. The source of the problem is in Case 5 int main { . I just dont know how...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.