Guest User

Untitled

a guest
Jan 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2. include ("../jpgraph.php"); //Sesuaikam dengan folder Anda
  3. include ("../jpgraph_bar.php"); //Sesuaikam dengan folder Anda
  4.  
  5. $dbid = mysql_connect('host_Anda', 'username_Anda', 'password_Anda');
  6. mysql_select_db('database_Anda',$dbid) or die ("Cannot find database");
  7.  
  8. $sql = mysql_query("SELECT * FROM data_grafik LIMIT 0,6");
  9. while($row = mysql_fetch_array($sql)){
  10. $data1[] = $row[0];
  11. $data2[] = $row[1];
  12. $data3[] = $row[2];
  13. }
  14.  
  15. // We need some data
  16. $b1plot = new BarPlot($data1);
  17. $b2plot = new BarPlot($data2);
  18. $b3plot = new BarPlot($data3);
  19.  
  20. // Setup the graph.
  21. $graph = new Graph(500,350,"auto");
  22. $graph->SetScale("textlin",0,20);
  23. $graph->img->SetMargin(25,85,25,25);
  24. $graph->SetBackgroundImage("bg.jpg",BGIMG_FILLPLOT); //"bg.jpg" bisa Anda ganti dengan background Anda.
  25. $graph->title->Set('"GRAFIK PERBANDINGAN JUMLAH PENDAFTAR PER-HARI"');
  26. $graph->title->SetColor('darkred');
  27. $graph->title->SetFont(FF_ARIAL);
  28. $graph->legend->Pos( 0.02,0.5,"right" ,"center");
  29.  
  30. // Setup font for axis
  31. $graph->xaxis->SetFont(FF_ARIAL);
  32. $graph->yaxis->SetFont(FF_ARIAL);
  33.  
  34. // Create the bar pot
  35. $b1plot->SetWidth(0.8);
  36. $b1plot->SetLegend("2006");
  37.  
  38. $b2plot->SetWidth(0.8);
  39. $b2plot->SetLegend("2007");
  40.  
  41. $b3plot->SetWidth(0.8);
  42. $b3plot->SetLegend("2008");
  43.  
  44. // Setup values
  45. $b1plot->value->Show();
  46. $b1plot->value->SetFormat('%d');
  47. $b1plot->value->SetFont(FF_TIMES);
  48. $b1plot->value->SetColor("navy");
  49.  
  50. $b2plot->value->Show();
  51. $b2plot->value->SetFormat('%d');
  52. $b2plot->value->SetFont(FF_TIMES);
  53. $b2plot->value->SetColor("olivedrab");
  54.  
  55. $b3plot->value->Show();
  56. $b3plot->value->SetFormat('%d');
  57. $b3plot->value->SetFont(FF_TIMES);
  58. $b3plot->value->SetColor("orangered");
  59.  
  60. // Setup color for gradient fill style
  61. $b1plot->SetFillGradient("navy","lightsteelblue",GRAD_WIDE_MIDVER);
  62. $b2plot->SetFillGradient("olivedrab","olivedrab1",GRAD_WIDE_MIDVER);
  63. $b3plot->SetFillGradient("orangered","khaki",GRAD_WIDE_MIDVER);
  64.  
  65. // Set color for the frame of each bar
  66. $b1plot->SetColor("navy");
  67. $b2plot->SetColor("olivedrab");
  68. $b3plot->SetColor("orangered");
  69.  
  70. //create the grouped bar plot
  71. $gbplot = new GroupBarPlot (array($b1plot ,$b2plot ,$b3plot));
  72. $graph->Add($gbplot);
  73.  
  74. // Finally send the graph to the browser
  75. $graph->Stroke();
  76. ?>
Add Comment
Please, Sign In to add comment