我是第一次使用 JPgraph,并尝试将 mysql 查询结果放入数组中,以获取基于示例 bargradsmallex4.php 的代码。我尝试过各种语法,但不太熟悉 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();
最佳答案
我对您的代码做了一些更改。
1- 设置 sum(current) 的 alice
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();
关于php - 将 mysql 结果导入 Jpgraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25988914/