0

I'm using JPgraph for the first time and trying to get mysql query results into the array for code based on the example bargradsmallex4.php. I've tried various syntax but not overly familiar with the mysql_fetch_array() and can't get it to insert data into the array. Any help would be appreciated. The query has been tested and produces results so it is not the query itself.

$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();
user3470715
  • 25
  • 1
  • 5

1 Answers1

0

I made some changes in your code.

1- Setting the alice for sum(current)

2- Setting the while loop and $datay array.

Please try it, hopefully it will gives you required output.

$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();
Jahanzeb
  • 613
  • 4
  • 11
  • I'm not getting errors with that but the result is a broken image link. I'm not sure if that is because the code above is wrong or because not all my paths are correct. I had to add the src folder to the existing paths for the require_once to work in the above file for example. – user3470715 Sep 23 '14 at 07:45
  • My examples work so I guess that indicates that the paths are not the issue. – user3470715 Sep 23 '14 at 08:08
  • @user3470715 If that is showing broken image, there must be some issue with your graph or its paths, etc. Adding a link here, you can take some help. http://stackoverflow.com/questions/6989701/jpgraph-wont-change-colors-on-my-barplot – Jahanzeb Sep 23 '14 at 09:00