【问题标题】:JPGraph Axis Error when trying to display data selected from Oracle Database尝试显示从 Oracle 数据库中选择的数据时出现 JPGraph 轴错误
【发布时间】:2020-06-14 06:49:15
【问题描述】:

目前正在尝试创建一个简单的 JPGraph,它从数据库中选择一条数据并将其显示在图表中。

我们遇到了一个错误:

JPGraph 错误 20544 - 无法使用自动缩放,因为它是不可能的 确定 Y 轴的有效最小值/最大值(仅限空值)。

我们真的很难理解这到底意味着什么。

这是我们的 PHP 代码:

<?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();
?>

所选数据的值为:205000000。

问题可能在于我们如何标记 y 轴刻度位置,但我们并不完全确定。

【问题讨论】:

    标签: php oracle jpgraph


    【解决方案1】:

    在您的 while 循环中,您不会将行数据中的值添加到您的 $data1y 数组中,因此最终结果是一个具有单个值的数组,从而导致您看到的错误。根据您的代码,您似乎想用数据库中的值填充 $data1y 数组,因此请使用下面的代码来执行此操作。

    #$data1y=array();  // you don't need this
    
    while ($row = oci_fetch_array($selectBudget, OCI_ASSOC+OCI_RETURN_NULLS)) {
        $data1y[] = $row['BUDGET'];
    }
    

    不清楚您试图用以下代码行做什么,但可能不需要。

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

    【讨论】:

    • 只是试图在条形图中显示一个值。我们更改了代码,现在错误变为:“Parameter must be an array or an object that implement Countable.”
    猜你喜欢
    • 2018-11-07
    • 2020-04-23
    • 1970-01-01
    • 2013-04-17
    • 2021-03-29
    • 2012-11-20
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多