我第一次使用JPgraph并尝试根据示例bargradsmallex4.php将mysql查询结果放入数组中。我尝试了各种语法,但对mysql_fetch_array()并不过分熟悉,也无法将数据插入到数组中。任何帮助,将不胜感激。该查询已经过测试并产生结果,因此它不是查询本身。
$sql= mysql_query('SELECT agency,current,sum(current)
FROM table2 WHERE MATCH(agency) AGAINST("health" IN BOOLEAN MODE) GROUP BY agency ');
// We need some data
$datay = array();
while($row = mysql_fetch_array($sql))
$datay[] = array(
'current' => $row['sum(current)'],
);
// Setup the graph.
$graph = new Graph(400,300);
$graph->SetScale("textlin");
$graph->img->SetMargin(25,15,25,25);
$graph->title->Set('"GRAD_VER"');
$graph->title->SetColor('darkred');
// Setup font for axis
$graph->xaxis->SetFont(FF_FONT1);
$graph->yaxis->SetFont(FF_FONT1);
// Create the bar pot
$bplot = new BarPlot($datay);
$bplot->SetWidth(0.6);
// Setup color for gradient fill style
$bplot->SetFillGradient("navy","lightsteelblue",GRAD_VER);
// Set color for the frame of each bar
$bplot->SetColor("navy");
$graph->Add($bplot);
// Finally send the graph to the browser
$graph->Stroke();
答案 0 :(得分:0)
我对您的代码进行了一些更改。
1-设置alice为sum(当前)
2-设置while循环和$ datay数组。
请尝试一下,希望它会为您提供所需的输出。
$sql= mysql_query('SELECT agency,current,sum(current) as sum_of_current FROM table2 WHERE MATCH(agency) AGAINST("health" IN BOOLEAN MODE) GROUP BY agency');
// We need some data
$datay = array();
while($row = mysql_fetch_array($sql)) {
$datay[] = $row['sum_of_current'];
}
// Setup the graph.
$graph = new Graph(400,300);
$graph->SetScale("textlin");
$graph->img->SetMargin(25,15,25,25);
$graph->title->Set('"GRAD_VER"');
$graph->title->SetColor('darkred');
// Setup font for axis
$graph->xaxis->SetFont(FF_FONT1);
$graph->yaxis->SetFont(FF_FONT1);
// Create the bar pot
$bplot = new BarPlot($datay);
$bplot->SetWidth(0.6);
// Setup color for gradient fill style
$bplot->SetFillGradient("navy","lightsteelblue",GRAD_VER);
// Set color for the frame of each bar
$bplot->SetColor("navy");
$graph->Add($bplot);
// Finally send the graph to the browser
$graph->Stroke();