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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

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

Post 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))
Last edited by ryuuka on Fri Sep 22, 2006 1:19 am, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post 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
Post Reply