|
 |
|
ถามเรื่องการดึงค่าจากฐานข้อมูล มาแสดงเป็น กราฟ โดยใช jpgraph |
|
 |
|
|
 |
 |
|
คือ มีแผนกอยู่ 5 แผนก แล้วผมต้องการสรุปการมาทำงานของแต่ละแผนกขึ้นมาเป็นกราฟ โดยจำนวนวันทำงานถูกเก็บอยู่ในฐานข้อมูล
ฐานข้อมูลจะมี id , full , current , stop
id = 1
dep = pp
full = 50
current = 45
stop = 5
id = 2
dep = qc
full = 10
current = 8
stop = 2
กราฟจะเป็นกราฟแท่ง แบบ 3 แท่ง
ผมทำแล้วมันโชว์แค่ค่าแรก เพราะผมไม่ทราบวิธีคิวรี่ข้อมูลแบบวนลูปในอาเรย์
ประมาณนี้ครับ
โค้ด
Code (PHP)
<?
mysql_select_db($database_db_man, $db_man);
$query_rs_man = "SELECT * FROM man";
$rs_man = mysql_query($query_rs_man, $db_man) or die(mysql_error());
$row_rs_man = mysql_fetch_assoc($rs_man);
$totalRows_rs_man = mysql_num_rows($rs_man);
$data1y=array($row_rs_man['full_rate']); //ผมคิดว่ามันต้องวนลูปตรงนี้เพื่อคิวรี่แผนกที่ 2 ขึ้นมา แต่ผมไม่ทราบว่าจะวนลูปยังไง
$data2y=array($row_rs_man['cur_rate']);
$data3y=array($row_rs_man['thai']);
// Create the graph. These two calls are always required
$graph = new Graph(850,400,'auto');
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135));
$graph->SetBox(false);
$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array('RM','B','C','D'));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
// Create the bar plots
$b1plot = new BarPlot($data1y);
$b2plot = new BarPlot($data2y);
$b3plot = new BarPlot($data3y);
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));
// ...and add it to the graPH
$graph->Add($gbplot);
$b1plot->SetColor("white");
$b1plot->SetFillColor("#cc1111");
$b2plot->SetColor("white");
$b2plot->SetFillColor("#11cccc");
$b3plot->SetColor("white");
$b3plot->SetFillColor("#1111cc");
$graph->title->Set("Bar Plots");
// Display the graph
$graph->Stroke();
?>
ขอบคุณครับ
Tag : PHP, MySQL, HTML/CSS, WebService

|
|
 |
 |
 |
 |
Date :
2012-03-23 17:50:30 |
By :
iiop |
View :
1550 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 05
|