Hi all.

I am trying to build a script that uses jpGraph, I have a php script that call another srcipt that contains the code to produce bar chart.

The script that holds the code to creat the bar chart call it data from an MySQL table.

The problem I am having is that I get an error "empty input data array specified for plot. Must have at least one data point".

The code I am using is:

require_once('../../Connections/conn.php'); 

include ("/jpGraph/jpgraph.php");
include ("/jpGraph/jpgraph_line.php");
include ("/jpGraph/jpgraph_bar.php");


   $SQL = "SELECT * FROM amember_baggagefound";
   $RESULT = mysql_query($SQL);
   if ($myrow=mysql_fetch_array($RESULT)) {
      do {
         $data[] = $myrow["f_baggage"];  //It would not create the graphs without using '[]' 
         $data_names[] = $myrow["member_id"]."(".$myrow["f_baggage"].")";
      }while ($myrow=mysql_fetch_array($RESULT));
   }

// Some data
$databary=array($data_names);
$months=$gDateLocale->GetShortMonth();

// New graph with a drop shadow
$graph = new Graph(600,200,'auto');
$graph->SetShadow();

// Use a "text" X-scale
$graph->SetScale("textlin");

// Specify X-labels
$graph->xaxis->SetTickLabels($months);

// Set title and subtitle
$graph->title->Set("Test Data");


// Use built in font
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Create the bar plot
$b1 = new BarPlot($databary[]);
$b1->SetLegend($data_names);


//$b1->SetAbsWidth(6);
//$b1->SetShadow();


// The order the plots are added determines who's ontop
$graph->Add($b1);
$graph->Stroke();

mysql_free_result($found);

Can anyone please advise me on where I am going wrong.

    Havent used jpgraph in a while but this line can't be accurate:

    $b1 = new BarPlot($databary[]);
    

    I think it should be:

    $b1 = new BarPlot($databary);
    

    ..because you set up the $databary array earlier.

      Hi cahva

      I made the change but I still get the same error.

      No matter what I change the error always kicks in.

      Do you have any other ideas, many thanks

        Well one thing that comes to my mind is this:

        $databary=array($data_names);
        
        // $data_names is already an array so try it with:
        $databary=$data_names;
        

        I really dont know what kind of information BarPlot needs. Read the documentation about that.

          Hi cahva

          Thanks for your reply, your right, I never spotted that I already had the array.

          Many thanks again

            Write a Reply...