Guest User

Untitled

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