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!

JPGraph Subform and Legend Issues

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
I have a JPGraph line plot inside a function and have showed below only the portions in question. The plot is working in pulling up multiple columns of data but I can't seem to get the legend to show properly, especially as there is also a sub form to selest what to graph. By default, all four columns are graphed, then there are checkboxes to pick more specifics. As it is, it shows all properly or I can pick only one at a time without a JPGraph crash (any two or more crashes it) but the main problem is in the legend, which has to get a title from a database table, shows all the titles for each column and it's obvious why but I'm not sure what to do about it! It's also showing all the same title so if two are being graphed, and there are four columns of data, I see the same file name eight times and it does not show the mark type.

I would also like it to show the column name at the peak of each graph.

Can anyone help?

Code:
if ($result = $mysqli->query("$Query")) :
	while ($row = $result->fetch_array()) :
		$datax[$row[0]][] = $row[1];
		$datay1[$row[0]][] = $row[2];
		$datay2[$row[0]][] = $row[3];
		$datay3[$row[0]][] = $row[4];
		$datay4[$row[0]][] = $row[5];
	endwhile;
	$result->close();
else:
	echo "<div class=\"Message\">\n";
	printf("MySQLi Error: %s\n", $mysqli->error);
	echo "</div>\n\n";
endif;

foreach($datay1 as $key=>$_datay): // for Legend
	$queryFN = "SELECT FileName FROM dcs_uploads ";
	$queryFN .= "WHERE ID = ".$key." ";
	$queryFN .= "ORDER by FileName";
	if ($result = $mysqli->query($queryFN)):
		$row = $result->fetch_row();
		$FileName = $row[0];
	endif;
endforeach;

if (!$SubData || $SubData == 'Red'):
	foreach($datay1 as $key=>$_datay): // for Red
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->mark->SetType(MARK_DIAMOND, 'red', 0.3);				
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->SetLegend(basename($FileName, ".csv"));
	endforeach;
endif;

if (!$SubData || $SubData == 'Gr'):
	foreach($datay2 as $key=>$_datay): // for Gr
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->mark->SetType(MARK_UTRIANGLE, 'green', 0.3);	
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->SetLegend(basename($FileName, ".csv"));
	endforeach;
endif;

if (!$SubData || $SubData == 'Gb'):
	foreach($datay3 as $key=>$_datay): // for Gb
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->mark->SetType(MARK_DTRIANGLE, 'teal', 0.3);	
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->SetLegend(basename($FileName, ".csv"));
	endforeach;
endif;

if (!$SubData || $SubData == 'B'):
	foreach($datay4 as $key=>$_datay): // for B
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->mark->SetType(MARK_SQUARE, 'blue', 0.3);	
		$lp[$key] = new LinePlot($_datay,$datax[$key]);
		$graph->Add($lp[$key]);
		$lp[$key]->SetLegend(basename($FileName, ".csv"));
	endforeach;
endif;
 
Thank you, I'll give these idea a try once I get to the office although this is my last half-day on the job so it's literally down to the wire today. You already have the data, I believe, as it is the same as I sent you directly a while back. No matter, I'll try these adjustments this morning to see if they help.

On the dashed and marks, I was saying that the marks are working as they should but the styles are not. The style is the same on every plot and so is the color. The color doesn't need to be specific to the chip color test but they do need to be different from one another to tell one plot from another and right now they are all the same. I could provide an array of possible column names that, if used in the query, could give a specific color range but it's probably not necessary.

I'm not sure what your presupposition meant as this needs to plot multiple Y-axis data from multiple columns. Yes, they can be on top of each other and, in fact, they need to be on top of each other but there could be any reasonable number of Y columns of data, which is the entire point of the code to handle a manually-entered query. Since the code can't know in advance what the query will look like or how many columns it might produce, it needs to loop though the Y-columns for however many there are and plot them.
 
number of plots is not the same as number of axes.
 
For X axis data, it should be based on the third column being submitted. The first is the file name, the second the file ID and the third is the X-axis data but their names could be anything. Those were the instructions I placed on the form as the basics to start (and I supplied a sample query pre-populated into the form) but any columns after that could be submitted as Y data.

So I changed $datax[$key] to $datax[$fileID] but it gives a plot of only a couple crisscross lines and nothing useful.

Did you mean to replace $i=0; with $i = $i == 4 ? 0 : $i; or to add it inside the foreach loop and leave the $i=0; where it is?


 
number of plots is not the same as number of axes.

I'm not sure what this means. There is an X-axis and there are multiple Y-axis and I have other plots that work this way. The only difference here is that the number of Y-axis plots is unknown and must be determined by the number of columns that the query produces. I can resolve the coloring issue and probably the line style issue myself but I am not sure how to handle the legend or the side-by-side plotting issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top