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 Out of Bounds 1

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
Try as I might, I can find no setting to use to keep a plot within the boundaries when manually submitting minimum/maximum X and Y values. The point was to try to zoom in on certain peaks but it always slides the X off into the grey title border on both the left and right sides. Instead I want it to stop within the plot area. In other words, if I set the minumum to 400, I want the plot to begin at 400 which it does but without still plotting lower values off the scale to the left.

This is just a fairly basic line plot. Any idea?

Code:
$graph = new Graph(800,450,"auto");
	$graph->SetImgFormat('png',60);
	$graph->img->SetAntiAliasing();

	$graph->SetScale('linlin');

	$graph->yaxis->scale->SetAutoMin($PlotYMin);
	$graph->yaxis->scale->SetAutoMax($PlotYMax);

	$graph->xaxis->scale->SetAutoMin($PlotXMin);
	$graph->xaxis->scale->SetAutoMax($PlotXMax);
 
nothing you can (I think) do except test the data as it goes through and reset the data when it is below minimum.

Code:
[i][COLOR=#9A1900]//assumes that the data is in $datax and $datay[/color][/i]
[b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'x'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'y'[/color][COLOR=#990000])[/color] [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$t[/color][COLOR=#990000]):[/color]
 [b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color]$[COLOR=#FF0000]{[/color][COLOR=#FF0000]"data"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$type[/color][COLOR=#FF0000]}[/color] [b][COLOR=#0000FF]as[/color][/b] [COLOR=#990000]&[/color][COLOR=#009900]$val[/color][COLOR=#990000]):[/color]
  [b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$val[/color] [COLOR=#990000]>[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]strtoupper[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$t[/color][COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Max"[/color][COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#009900]$val[/color] [COLOR=#990000]=[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$type[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Max"[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color]
  [b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$val[/color] [COLOR=#990000]<[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]strtoupper[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$t[/color][COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Min"[/color][COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#009900]$val[/color] [COLOR=#990000]=[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$type[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Min"[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color]
 [b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
[b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
 
That's what I as beginning to think too. So, with the presumption that $datay is actually, $datay1, $datay2, etc., how can this be done? It's mainly X that is the issue but it I truncate it, Y would need the same thing or JPGraph will protest.
 
Where is the variable $type coming from? Should it be $t instead?
 
yes sorry
for multiple $datay values something like this might work

Code:
[i][COLOR=#9A1900]//assumes that the data is in $datax and $datay[/color][/i]
[b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'x'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'y'[/color][COLOR=#990000])[/color] [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$t[/color][COLOR=#990000]):[/color]
 [b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color]$[COLOR=#FF0000]{[/color][COLOR=#FF0000]"data"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$t[/color][COLOR=#FF0000]}[/color] [b][COLOR=#0000FF]as[/color][/b] [COLOR=#990000]&[/color][COLOR=#009900]$val[/color][COLOR=#990000]):[/color]
  [b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]is_array[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$val[/color][COLOR=#990000])):[/color]
[tab][b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$val[/color] [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$v[/color][COLOR=#990000]):[/color]
[tab]  [b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$v[/color] [COLOR=#990000]>[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]strtoupper[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$t[/color][COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Max"[/color][COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#009900]$v[/color] [COLOR=#990000]=[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$type[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Max"[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color]
[tab]  [b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$v[/color] [COLOR=#990000]<[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]strtoupper[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$t[/color][COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Min"[/color][COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#009900]$v[/color] [COLOR=#990000]=[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$type[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Min"[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color]
[tab][b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
   [b][COLOR=#0000FF]else[/color][/b][COLOR=#990000]:[/color]
[tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$val[/color] [COLOR=#990000]>[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]strtoupper[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$t[/color][COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Max"[/color][COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#009900]$val[/color] [COLOR=#990000]=[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$type[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Max"[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color]
[tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$val[/color] [COLOR=#990000]<[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]strtoupper[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$t[/color][COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Min"[/color][COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#009900]$val[/color] [COLOR=#990000]=[/color] $[COLOR=#FF0000]{[/color][COLOR=#FF0000]"Plot"[/color] [COLOR=#990000].[/color] [COLOR=#009900]$type[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]"Min"[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color]
   [b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
  [b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
[b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
 
What I ended up doing was to add a BETWEEN to the query itself while, at the same time, submitting the min and max values to the plot. It seems to work well and no longer scrolls off the image! Thank you.
 
depending on your data type and what you are trying to get the curve to show, selecting only values between limits might well skew the curve inappropriately.

the method I posted was crude but at least the values were plotted.

you could emulate the reset within the query of course

Code:
SELECT
	case
		when val > maxVal
		then maxVal
		when val < minVal
		then minVal
		else val
	end as adjustedValue
FROM
	table
 
Thank you. The engineers, however, do not believe it is a problem in this case. It is not so much the curve that interests them as it is the comparison between the different Y values although if there were some other way to zoom in to a portion of the plot (like a magnifying glass) it would be ever better. Anyway, because Y is logarithmic, I was able only to limit the X values for them.
 
Zooming the curve should be easy enough. Two methods spring to mind

1. Use a much bigger canvas and limit the display size in the IMg tag. The use jquery loupe to zoom in on sections of the curve.
2. Put a couple of jquery sliders in to allow the user to select ranges of interest as part of the filter. Then use those values in your query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top