please help me guys, i need to know how is it possible to make a line graph using php/javascrip/html. data will be coming from a live database, so basically the webpage will just plot the data coming from the database, but the problem is that, even the basic know-how's i dont know...

any help would be very much appreciated..^_^

7 Years
Discussion Span
Last Post by julzk

Simple, I personally use http://www.maani.us/xml_charts/

You can use it to display any database data as a pretty chart. Highly customizable. Basically you use a php script to pull the data from your SQL database and it outputs the data as an XML file that shows it as a pretty graph of your choice which is also very flexible.

Look at this code example:


//connect to the database 
mysql_connect ( "host", "user", "password" );
mysql_select_db ( "Accounting" );

//start the XML output 
print "<chart>";
print "<chart_data>";

//output the first row that contains the years 
print "<row>";
print "<null/>";
$category = mysql_query ("SELECT Year FROM Growth GROUP BY Year ORDER BY Year");
for ( $column=0; $column < mysql_num_rows($category); $column++ ) {
	print "<string>".mysql_result ( $category, $column, "Year")."</string>";
print "</row>";

//output row 2 to 4. Each row contains a region name and its data 
$series = mysql_query ("SELECT Region FROM Growth GROUP BY Region ORDER BY Region");      
for ( $row=0; $row < mysql_num_rows($series); $row++ ) {
	print "<row>";
	$region = mysql_result ( $series, $row, "Region");
	print "<string>$region</string>";
	$data = mysql_query ("SELECT Revenue FROM Growth WHERE Region='$region' ORDER BY Year");      
	for ( $column=0; $column < mysql_num_rows($data); $column++ ) {
		print "<number>".mysql_result ( $data, $column, "Revenue")."</number>";
	print "</row>";

//finish the XML output 
print "</chart_data>";
print "</chart>";

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.