php - 将 mysql 结果导入 Jpgraph

标签 php mysql sql jpgraph

我是第一次使用 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/

相关文章:

php - 在codeigniter和mysql中过滤多个时间段的sql记录?

php - 在php中导入mysql数据库时如何检查csv列名称与mysql列

php - require_once "../../file/config.php"是在现代标准(2013)中隐藏我的配置文件的最安全方式吗?

PHP - strlen 不工作

php - 使用 PHP 和 MySQL 的分组/分层报告

php时间处理NULL为00 :00:00

sql - 获取sql中不同的记录

sql - 如何查找键重复但所有列中不重复的行?

php - 如何在 Laravel 5 中仅对数据库表中的特定记录使用唯一验证?

php - 将 3 个表中的数据显示为菜单