Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Inside JPGraph Function

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
I'm having some difficulty in getting a scatter plot to work properly after making a slight change to the query. The query itself works fine and fetches only two or three records (or however many are selected through a form) and it is graphing but there is a foreach loop to go through an array of key values that shows every entry in the system, not simply the couple selected.

There are three fields being selected. The first contains the FileID which differenciates between one set of data and the next; the second two are the X and Y respectively. The multidimensional array from the query is:

Code:
if ($result = $mysqli->query("$Query")) :
	while ($row = $result->fetch_array()) :
		$datax[$row[1]][] = $row[1];
		$datay[$row[1]][] = $row[2];
	endwhile;
	$result->close();
else :
	$Output .= "<div class=\"Message\">\n";
	$Output .= printf("MySQLi Error: %s\n", $mysqli->error);
	$Output .= "</div>\n\n";
endif;

Then the foreach loop in which I am having the problems is here:

Code:
$colors = array('yellow','black','blue','red','green','purple','lightblue');
$marks = array('MARK_SQUARE','MARK_UTRIANGLE','MARK_DTRIANGLE','MARK_DIAMOND','MARK_FILLEDCIRCLE','MARK_STAR');

foreach($datay as $key=>$_datay):
[COLOR=red][bold]// I tried to fetch the file name through the main $Query as a fourth value 
// rather than creating a new query but it breaks when I try to access it, which I thought might 
// be because each one is indeed in the data stream multiple times. If I can use it here, though, 
// I would prefer it to the extra query.[/bold][/color]
	$queryFN = "SELECT DISTINCT FileName FROM file_uploads WHERE ID IN (".$key.") GROUP BY FileName ORDER by FileName";
		if ($result = $mysqli->query($queryFN)):
			$rowname = $result->fetch_row();
			$FileName = $rowname[0];
		endif;
	//$Output .= "Key values :" . $key."<br>\n";
	
	$sp[$key] = new ScatterPlot($_datay,$datax[$key]);
	$graph->Add($sp[$key]);
	$sp[$key]->mark->SetType( isset($marks[$key]) ? $marks[$key] : $marks[0] );			
	$sp[$key]->mark->SetFillColor( isset($colors[$key]) ? $colors[$key] : $colors[0] );
	$sp[$key]->mark->SetWidth(3);

	$sp[$key]->SetLegend(basename($FileName, ".csv"));
endforeach;

The resulting legend shows every file in the database and also the mark->SetType does not work at all. There are no error messages but there is also no plot when it is not remarked out.

Finally, the color array seems to start somewhere randomly in the middle, then go back to the beginning and make every legend after be yellow. If I echo the $key to the screen inside the loop, it confirms that all are showing. I need it to start at the beginning, then repeat if necessary back at the beginning if there are that many selections. It would be rare that there are that many but having it start in the middle, then having every one be yellow after the end, doesn't work either.

Any ideas what I've done wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top