JPGraph Axis Error when trying to display data selected from Oracle Database

161 Views Asked by At

Currently trying to create a simple JPGraph that selects a piece of data from a database and displays it in a graph.

We have run into an error:

JPGraph Error 20544 - Cannot use auto-scaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).

We're really struggling to understand exactly what this means.

Here's our PHP code:

<?php

$conn = oci_connect('connection_name', 'Groupassignment2020', 'db_link');

if (!$conn) {   

$e = oci_error();   

trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

require_once ('src/jpgraph.php');
require_once ('src/jpgraph_bar.php');

$selectBudget = oci_parse($conn, "SELECT BUDGET FROM REVENUE");
oci_execute($selectBudget);

$data1y=array();

while ($row = oci_fetch_array($selectBudget, OCI_ASSOC+OCI_RETURN_NULLS)) {
    $data1y = $row['BUDGET'];
}

$data1y=array($selectBudget,$selectBudget);


// Create the graph. These two calls are always required
$graph = new Graph(1400,800,'auto');
$graph->SetScale("textlin");

// Create the bar plots
$b1plot = new BarPlot($data1y);

$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);

$graph->yaxis->SetTickPositions(array(0,1000000,205000000), array(0,1000000,205000000));
$graph->SetBox(false);

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot));
// ...and add it to the graPH
$graph->Add($gbplot);

$b1plot->SetColor("white");
$b1plot->SetFillColor("#768692");

$graph->title->Set("Bar Plots");

// Display the graph
$graph->Stroke();
?>

The value of the selected data is: 205000000.

Possibly the issue is how we have labeled the y-axis Tick Positions but we're not entirely sure.

1

There are 1 best solutions below

1
Dave On

In your while loop you are not adding values from the row data to your $data1y array so the end result is an array with a single value resulting in the error you are seeing. Based on your code it looks like you want to fill the $data1y array with values from your database so use the code below to do that.

#$data1y=array();  // you don't need this

while ($row = oci_fetch_array($selectBudget, OCI_ASSOC+OCI_RETURN_NULLS)) {
    $data1y[] = $row['BUDGET'];
}

It isn't clear what you were trying to do with the following line of code but it probably isn't needed.

#$data1y=array($selectBudget,$selectBudget);  // probably don't need this either