Chart control in PHP and MySQL using JpGraph

How to install jpgraph ?
 
Step 1
 
At first Download jpgraph.Then Copy and paste this file in your C drive.
 
 
 
 
C:\php\pear> 
 
 
 
You can also download it from attached file.
 
Step 2
 
Create a new database into mysql database..
 
 
 
Step 3
 
Then Create a new php file called (lin.php)
 
The code is shown below.
  1. <?php  
  2. require_once('jpgraph/jpgraph.php');  
  3. require_once('jpgraph/jpgraph_line.php');  
  4. require_once('jpgraph/jpgraph_bar.php');  
  5. $x_axis = array();  
  6. $y_axis = array();  
  7. $i      = 0;  
  8. $con    = mysqli_connect("localhost""root""""test");  
  9. // Check connection  
  10. if (mysqli_connect_errno()) {  
  11.     echo "Failed to connect to MySQL: " . mysqli_connect_error();  
  12. }  
  13. $result = mysqli_query($con"SELECT * FROM tbl_grp");  
  14. while ($row = mysqli_fetch_array($result)) {  
  15.     $x_axis[$i] = $row["exam_no"];  
  16.     $y_axis[$i] = $row["mrk"];  
  17.     $i++;  
  18. }  
  19. mysqli_close($con);  
  20. $width  = 600;  
  21. $height = 200;  
  22. $graph  = new Graph($width$height);  
  23. $graph->SetScale('textint');  
  24. $graph->title->Set('My Example');  
  25. $graph->xaxis->title->Set('(year)');  
  26. $graph->xaxis->SetTickLabels($x_axis);  
  27. $graph->yaxis->title->Set('(# example)');  
  28. $barplot = new BarPlot($y_axis);  
  29. $graph->Add($barplot);  
  30. $graph->Stroke();  
  31. ?>  
Open your Browser and see.
 
 
 
Thanks.
Ebook Download
View all
Learn
View all