scales11 Posted August 24, 2012 Share Posted August 24, 2012 Hi all. I am having a simple problem with jpgraph. I have two files and I would like to pass a variable from one file to another(a jpgraph script with CSIM) so that it can be used to plot a chart. Below are my two files: main.php: <html> Before plot: <br> <?php $tempy=array(5,4,3,2,1); $tempx=array(1,2,3,4,5); include "temp3.php"; ?> <br> After </html> temp3.php: <?php include ('/lib/jpgraph/jpgraph.php'); include ('/lib/jpgraph/jpgraph_line.php'); include ('/lib/jpgraph/jpgraph_date.php'); // Create the graph $graph = new Graph(700,500); $graph->SetScale('datlin'); // Create the linear plots $lp=array(); $lp=new LinePlot($tempy,$tempx); $lp->SetColor('blue'); $lp->mark->SetType(MARK_FILLEDCIRCLE); $lp->mark->SetFillColor('red'); //print_r($lp); // Add the plot to the graph $graph->Add($lp); // Display the graph $graph->StrokeCSIM('temp3.php'); ?> Jpgraph ends up showing me a huge error(25121): "empty input data array specified for plot. Must have at least one data point." I know that the data is getting through somehow, because if I change the length of $tempx to an array of 6 numbers, then jpgraph complains that both arrays are not of equal size..WEIRD?! Can anyone help me out? I don't even need to pass an array, I can also make it work if I am just able to pass a single variable (since I want to get the data from a specific database and I could just pass the table name). Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/ Share on other sites More sharing options...
scales11 Posted August 24, 2012 Author Share Posted August 24, 2012 Here is some example results: first attempt:(this is what I want to get working) second attempt: third attempt: Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372110 Share on other sites More sharing options...
Jessica Posted August 24, 2012 Share Posted August 24, 2012 You should probably ask the makers of jGraph. I read their docs and it looks fine to me, based on what I read in a few minutes. Did you pay for the version? Either way they should offer some support. This thread should be moved to Third Party software. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372115 Share on other sites More sharing options...
scales11 Posted August 24, 2012 Author Share Posted August 24, 2012 Unfortunately, I cannot find any support for jpgraph other than the howto and documentation. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372131 Share on other sites More sharing options...
Jessica Posted August 24, 2012 Share Posted August 24, 2012 Edit: I guess that's a different company. However, on the correct company's site, there's this example: http://jpgraph.net/features/src/show-example.php?target=new_line1.php Which shows 3 lines, with different syntax than yours. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372132 Share on other sites More sharing options...
scales11 Posted August 24, 2012 Author Share Posted August 24, 2012 close...but that is jgraph...not jpgraph Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372133 Share on other sites More sharing options...
MMDE Posted August 24, 2012 Share Posted August 24, 2012 Unfortunately, I cannot find any support for jpgraph other than the howto and documentation. I have never used jpgraph. You could try to create your own. http://www.php.net/manual/en/ref.image.php Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372134 Share on other sites More sharing options...
scales11 Posted August 24, 2012 Author Share Posted August 24, 2012 Unfortunately, I cannot find any support for jpgraph other than the howto and documentation. I have never used jpgraph. You could try to create your own. You are missing the point of the example I am showing. Initially (attempt 1) I did have the same amount of data in the x and y arrays. I only changed one to be larger so that I could show that the data was getting sent to jpgraph. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372136 Share on other sites More sharing options...
PFMaBiSmAd Posted August 25, 2012 Share Posted August 25, 2012 I tried your code and it doesn't produce that 25121 ... error. I could only produce that error when the first parameter in the LinePlot($tempy,$tempx) statement doesn't exist. I'm going to guess that you have multiple temp3.php files at different paths on the server (or perhaps different main.php files) and php is finding the wrong one, one that is using a different variable name for the first parameter than what you are actually setting. Using include 'temp3.php'; causes php to search the include_path to find the file. You can use include './temp3.php'; to force php to ignore the include_path and look in the current folder. This would also indicate that your include_path setting doesn't have a . (dot) as the first setting to cause php to look first in the current folder. Do you have php's error_reporting set to E_ALL and display_errors set to ON (and output_buffering set to OFF) so that php will report and display all the errors it detects. When I caused the first parameter variable to not exist/mismatch what was being used in the LinePlot() statement, I got an expected php error - Notice: Undefined variable: tempy in ... \temp3.php on line 14, followed by the JpGraph Error: 25121 ... Edit: Also, the full path that would be displayed in the php Notice: ... message would identify exactly where the temp3.php file is at, that php using. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372309 Share on other sites More sharing options...
PFMaBiSmAd Posted August 25, 2012 Share Posted August 25, 2012 I have just reviewed the code and images of code you have been posting and you are changing variable names ($tempy, $datay) and the name of the posted include file (temp3.php, temp4.php) and don't have a proper match between all of them. So, I can easily see you setting one variable name in the main.php file and the actual file you are including (apparently temp3.php in all cases) is using a different variable name. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372311 Share on other sites More sharing options...
scales11 Posted August 25, 2012 Author Share Posted August 25, 2012 I have just reviewed the code and images of code you have been posting and you are changing variable names ($tempy, $datay) and the name of the posted include file (temp3.php, temp4.php) and don't have a proper match between all of them. So, I can easily see you setting one variable name in the main.php file and the actual file you are including (apparently temp3.php in all cases) is using a different variable name. Ahh, you are somewhat correct in this case...I mis-typed the proper label in the header (I titled it temp4.php when it should have been temp3.php) Unfortunately, this was the only place I mis-typed the file name and I actually have the file named temp3.php and it is the only one of its name in the folder. I was not however, using the "./" before the include. I shall give that a try and double check my variables as you suggest to see if I made a mistake. I shall report back. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372316 Share on other sites More sharing options...
scales11 Posted August 26, 2012 Author Share Posted August 26, 2012 I tried your code and it doesn't produce that 25121 ... error. I could only produce that error when the first parameter in the LinePlot($tempy,$tempx) statement doesn't exist. I'm going to guess that you have multiple temp3.php files at different paths on the server (or perhaps different main.php files) and php is finding the wrong one, one that is using a different variable name for the first parameter than what you are actually setting. Using include 'temp3.php'; causes php to search the include_path to find the file. You can use include './temp3.php'; to force php to ignore the include_path and look in the current folder. This would also indicate that your include_path setting doesn't have a . (dot) as the first setting to cause php to look first in the current folder. Do you have php's error_reporting set to E_ALL and display_errors set to ON (and output_buffering set to OFF) so that php will report and display all the errors it detects. When I caused the first parameter variable to not exist/mismatch what was being used in the LinePlot() statement, I got an expected php error - Notice: Undefined variable: tempy in ... \temp3.php on line 14, followed by the JpGraph Error: 25121 ... Edit: Also, the full path that would be displayed in the php Notice: ... message would identify exactly where the temp3.php file is at, that php using. Ok, I just setup a fresh server. I installed jpgraph v3.5.0b1, and used the following two files: <?php // plot.php require_once ('./jpgraph/jpgraph.php'); require_once ('./jpgraph/jpgraph_line.php'); require_once ('./jpgraph/jpgraph_date.php'); $graph = new Graph(500,400,'auto'); $graph->SetScale('lin'); $sp1 = new LinePlot($datay,$datax); // Add the plot $graph->Add($sp1); $graph->StrokeCSIM('plot.php'); ?> <html> before <br> <?php // main.php $datay = array(2,3,2,3,4); $datax = array(1,2,3,4,5); include "./plot.php"; ?> <br> after </html> I am still getting the same result... Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372449 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2012 Share Posted August 26, 2012 I finally know enough about what jpgraph is doing to tell you why the data doesn't exist when jpgraph is trying to produce the image. When you call the ->StrokeCSIM() method when a page is first requested, it outputs HTML consisting of a <map></map> tag and an <img > tag. The URL in the image tag is that of the included file (plot.php). When the browser tries to fetch the image to display it in the <img > tag, it is only requesting plot.php. Since the data is being defined in your main file, it does not exist in plot.php. If you need to use your current scheme of having a main file that defines the data and an included file that uses the data, you would need to supply the name of your main file as a parameter to the ->StrokeCSIM(...) method. You would also need to add conditional logic in your code so that when the page is requested due to the <img > tag, that you don't output any content yourself before the header/image data that ->StrokeCSIM() outputs. When I tried this, the URL in the <img tag has a ?_jpg_csimd=1 get parameter on the end of the URL. You would need to detect this and prevent any output from your script. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372473 Share on other sites More sharing options...
scales11 Posted August 26, 2012 Author Share Posted August 26, 2012 I finally know enough about what jpgraph is doing to tell you why the data doesn't exist when jpgraph is trying to produce the image. When you call the ->StrokeCSIM() method when a page is first requested, it outputs HTML consisting of a <map></map> tag and an <img > tag. The URL in the image tag is that of the included file (plot.php). When the browser tries to fetch the image to display it in the <img > tag, it is only requesting plot.php. Since the data is being defined in your main file, it does not exist in plot.php. If you need to use your current scheme of having a main file that defines the data and an included file that uses the data, you would need to supply the name of your main file as a parameter to the ->StrokeCSIM(...) method. You would also need to add conditional logic in your code so that when the page is requested due to the <img > tag, that you don't output any content yourself before the header/image data that ->StrokeCSIM() outputs. When I tried this, the URL in the <img tag has a ?_jpg_csimd=1 get parameter on the end of the URL. You would need to detect this and prevent any output from your script. Well thank you very much for taking the time to help me figure out what is going on. I am still a bit of a newb to php but I think I understand some. So, I have another problem/question then. If I replace StrokeCSIM('plot.php'); with Stroke();, I get a broken image. Does your explanation hold true for that scenario as well? Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372532 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2012 Share Posted August 26, 2012 Yes. The code on your page is currently outputting HTML, the <html>before<br>, before outputting the image using the ->Stroke()/->StrokeSCIM() method, which outputs a content-type header followed by the image data. The HTML that is output first prevents the content-type header from working (assuming that output buffering is turned off in your php.ini) or it becomes part of the image data (if output buffering is turned on in your php.ini.) In either case, the http request for an image doesn't return the proper data. Edit: The conditional logic I mentioned for the ->StrokeSCIM() method would allow this HTML to be output when the page is requested as a web page, but prevent it when the page is requested as a dynamic image. If you have the error_reporting/display_errors settings set as suggested above, you would be getting a header error ... output started at ... message that would help debug problems with this. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372545 Share on other sites More sharing options...
scales11 Posted August 26, 2012 Author Share Posted August 26, 2012 OK. Can you give me an example of the conditional logic? Then I can look up more and try and make it work. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372597 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2012 Share Posted August 26, 2012 Let's take a step back. Why are you including your plot.php file into another file, rather than having all of the code/data needed to call the jpgraph functions in only the plot.php file? That's how you would normally dynamically produce an image (using the ->Stroke() method) and you would output it on a web page by putting the URL of the code that results in the image being output into an <img src='plot.php' alt=''> tag. If you don't actually have a web page yet, you can browse directly to the URL of the code that results in the image being output, which is probably how you are doing this for testing. For what you are doing with two files, a main file that includes your plot.php file, and for the ->Stroke() method, you would need to put the URL of your main file into the <img tag. Your main file and the plot.php file cannot output anything to browser except the content-type header and the image data, which is what the ->Stroke() method does. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372731 Share on other sites More sharing options...
scales11 Posted August 26, 2012 Author Share Posted August 26, 2012 Well that is probably a better question. As I mentioned I am still new to PHP so there may be a better way to accomplish this. I have a table of data (in a sql server database) that I will be storing my x and y data in, for several plots. I decided that rather than create a bunch of .php files to make the plots, I would have a generic plot that I would call and pass the data (along with other parameters such as scale values, labels, and titles) to. This is the reason why I was trying to use the ?include? statement rather than calling a different php file each time I wanted to view a plot (with data). I also will be using the CSIM type of plot so that I can make the data clickable in order to launch other commands based on specific data points, ie. Changing and commenting them. In order to do this, I will have to use the ?include? statement (or so I thought). I am able to get the CSIM and image-mapping correct, provided that I do not pass any variables to the plot, meaning that I will need several plots and will be ?including? different ones based upon what is desired. Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372740 Share on other sites More sharing options...
PFMaBiSmAd Posted August 27, 2012 Share Posted August 27, 2012 There's nothing wrong with that method, except the html you are trying to output. The short-answer (to Life, the Universe, and Everything) is that the only thing you can output to the browser for a dynamically produced image is the Content-type header, followed by the binary image data. The HTML you have in your main.php file - <html> before <br> and <br> after </html> will have to be removed from the main.php file or you will have to put it (the html) inside of a conditional if(){} statement so that it is not output when the dynamically produced image is being output. To make an actual web page, with html markup, you would need to include your main.php file into that web page and then pass the main.php file to the ->StrokeCSIM('main.php') method so that it will use main.php as the URL in the <img tag. Quote Link to comment https://forums.phpfreaks.com/topic/267523-include-variables-and-jpgraph/#findComment-1372915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.