Page 1 of 1

[SOLVED]Problem with php and array (and JPgraph)

Posted: Thu Sep 21, 2006 6:15 am
by ryuuka
k new prob for me
i get a few values from the DB and i put it into an array what should happen next is
that the said values from the array don't get into the graph and thus no graph is displayed
saying there are no values.
personally i think there are no values coming from the query. This is the code.
load percentage has the the values from the cpu load (1% to 100%)

incase none are familiar with JPgraph i put what the lines are supposed to do in the comment.

Code: Select all

<?php

//report errors
error_reporting(E_ALL); 
ini_set('display_errors', TRUE);

//include these for a correct build up of the graphs
  include ("../system/jpgraph-2.1.2/src/jpgraph.php");
  include ("../system/jpgraph-2.1.2/src/jpgraph_line.php");
   
 $objConn = new COM("adodb.connection");
 $objConn->Open

("dsn=Gispen_Inventory;server=@@@@@.@@@@@@;database=@@@@_ICT;Trusted_Connection=yes"); 
    $rs = $objConn->Execute("SELECT TOP 30  LoadPercentage, LastCheck, ServerName
                                FROM dbo.@@@@_Server_CPU_gebruik
                                WHERE (ServerName = 'DC0001')
                                ORDER BY LastCheck DESC");
// getting the data from the query here
     while (!$rs->EOF) 
      {
        $s_LastCheck      = $rs->Fields['LastCheck']->value;
        $s_ServerName     = $rs->Fields['ServerName']->value;
        $s_LoadPercentage = $rs->Fields['LoadPercentage']->value;
        
       $rs->MoveNext();
      }  

              // Creating the graph here
              $graph = new Graph(350,250,"auto");	

              // setting scale here
              $graph->SetScale( "textlin",0,100 );
              // this is the graph name
              $graph->title->Set ("$s_ServerName");
              // names for the axis
              $graph->xaxis-> title->Set("horizontaal" ); 
              $graph->yaxis-> title->Set("verticaal" ); 

              // here is the line created according to 
              // the data in the variable
              $lineplot=new LinePlot($s_LoadPercentage);

              // show the values and set the color to blue
              $lineplot->SetColor("blue");
              $lineplot->value-> Show();
              
              // Add the plot to the graph
              $graph->Add($lineplot);

              // Display the graph
              $graph->Stroke();
          
  ?>
For those that have understanding of JPgraph this is the error i get:

A plot has an illigal scale. this could for example be that you are trying to use auto scaling to draw a lineplot with only 1 point or that the plot area is to small.
It could also be that no input data value is numeric (perhaps only '-' or 'x')

(All input data is numeric. it has more than 1 point and the area is not to small(i think))

Posted: Thu Sep 21, 2006 10:08 am
by pickle
Is $s_LoadPercentage the array of values you're looking for? Because right now it'll be scalar - you just keep overwriting it's value. If you want an array, use $s_LoadPercentage[] instead.

You also spelled 'horizontal' wrong for the title of your x-axis.

Posted: Fri Sep 22, 2006 1:18 am
by ryuuka
thanks it works now
sample for future visitors:

Code: Select all

while (!$rs->EOF) 
      { 
        $s_LastCheck[]      = $rs->Fields['LastCheck']->value; 
        $s_ServerName[]     = $rs->Fields['ServerName']->value; 
        $s_LoadPercentage[] = $rs->Fields['LoadPercentage']->value; 
        
       $rs->MoveNext(); 
      }
[] is placing the retrieved numbers in an array wich is needed to make the graph work