Your second array looks good. Each entry is an array with 3 elements: a label string, which you can leave empty, then X, then Y. This will work with data type 'data-data'. (Your first array won't work because it doesn't leave a slot for the labels. You need those slots, even if you don't use the labels.)
Note that the DrawGraph() method does not take any arguments - PHP will not report this as an error but PHPlot ignores the 800,800. I assume you created a PHPlot object called 'plot' somewhere above the code you posted (that is where you can specify the dimensions of the image).
If none of this helps, could you post the error message you are seeing?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, no, that error doesn't help. What you are looking for is the error logged by the web server in response to the URL request for the PHP script that draws the plot. (That can be hard to get in some hosting situations, but there just isn't any other place PHP will record the actual errors, if you are using a web server.)
I took your script, added a require_once for phplot.php, replaced your function to get the data with a data array using some of your numbers from above, and I get a good plot. I don't think your function is returning a bad data array - PHPlot really should catch all those cases and tell you about them with an error image. So that leaves something wrong outside of the script.
If you can get to the web server error log, it should clear this up. If not, there are other things we can try.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks again but I'm afraid we are at the "do something else" stage. There is nothing in the httpd error log relating to this script. I don't see how something outside the script can cause the problem as I am not using any global variables so there cannot be any conflict there. I do have a number of functions defined but it would seem like a long shot that one of those conflict and I would think PHP would complain. Anyway it looks like everything is OOP so your function calls would presumably never leave the realm of your class.
Last edit: gw1500se 2014-08-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is an FYI to confirm that there is something on my page, outside of PHPlot, that is causing the problem. I commented out my calls and added the sample plot in the distro. It works fine outside my page but fails the same way on my page.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know why PHP error messages aren't showing up in your web server error log, but you might want to run some checks to find out (because it can be very hard to debug anything otherwise).
Back to phplot, here is something you can try. Change the PHP script (the one that makes the PHPlot) to include this line way at the top - before the first code line:
ini_set('display_errors', 'on');
Now point your browser directly to that PHP script - not to the HTML page that references it. (This gets around the issue when the page is accessed through an IMG tag: the browser expects an image and will not display any error text that comes back instead.) You should get either a PHP error, or a plot image.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First, PHP errors are indeed sent to the log, just none for PHPlot. Second, I don't think I understand your instructions. I have always pointed the browser to the PHP script as that is the only way to display any HTML.
Inserting the ini_set command was the first think I tried but the image page with the error is all that I can get.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(Sorry, my mistake. I see now that your error message - "The image cannot be displayed" - would only be seen if the browser pointed right to the image file, not to an HTML wrapper script.)
I duplicated the behavior you are seeing by introducing an error into a PHPlot script. I am getting the exact same browser error, with nothing in my Apache error log. I tried this with both PHP-5.5.15 and PHP-5.4.31, and I don't understand it. It should be logging a "headers already sent" error, because I had my script produce some text output before DrawGraph(), which is a common error. I know I've done this before and had the error logged, but it isn't happening now. Instead, I get only the browser message, because the response is invalid (my text followed by the PNG image data).
I am going to look into this - see if there was some change in PHP or Apache. But in the meantime, please look over your script carefully and make sure you are not generating any output before $plot->DrawGraph(). That means no echo or print, and nothing at all outside of the PHP opening tag (<?php). Even a blank line or a single space at the top of your script before the opening tag will produce this condition.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure what you mean by "putting the PHPlot into an image". Anyway, this is what I learned about the lack of error message in the case I found.
If the PHP configuration setting output_buffering is set to On or a number (like 4096, as in the supplied sample php.ini files), then the output is buffered, and sending headers works even if out of order. That means if a PHPlot script produces output before DrawGraph() (which sends the Content-Type header), then there is no PHP error logged, and the output - which is not valid, because it has text before the image - is sent to the browser. Not ideal.
If output_buffering is off, which is not recommended, then the same script error will result in an error recorded: PHP Warning: Cannot modify header information - headers already sent by .... This message shows you where in the script the incorrect output came from, which is very helpful.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What I meant was that the plot script was set as the src attribute of an image tag. Instead I was calling it inline with the rest of my php code on the page. I needed to separate the plot code into a separate file and then put that file as the source for the image tag. Just being dumb.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not dumb, but yes it won't work that way. However, there is a way to do it like that - with a single script - if you want, using EncodeImage and the "data URL scheme".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying PHPlot for the first time and cannot get to first base. The sample plots all work but my data produces a generic error. Here is my code:
$plot->SetDataValues(findZArray($overall,$meanO,$stddeviationO));
$plot->SetTitle("Standard Deviation of Scores (Overall)");
$plot->SetXTitle('Standard Deviation');
$plot->SetYTitle('Scores');
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->DrawGraph(800,800);
The content (print_r) of findZArray is:
Array
(
[0] => Array
(
[0] => 4.6769216411499
[1] => 694.2172
)
)
Can someone tell me what I'm doing wrong? TIA.
Last edit: gw1500se 2014-08-19
I thought I had it by changing to data-data array but that did not work either. Now the array looks like:
Array
(
...
The data types for the array are very confusing. It seems there is no way to pass simple xy coordinate pairs that are both numbers. What am I missing?
Last edit: gw1500se 2014-08-19
Your second array looks good. Each entry is an array with 3 elements: a label string, which you can leave empty, then X, then Y. This will work with data type 'data-data'. (Your first array won't work because it doesn't leave a slot for the labels. You need those slots, even if you don't use the labels.)
Note that the DrawGraph() method does not take any arguments - PHP will not report this as an error but PHPlot ignores the 800,800. I assume you created a PHPlot object called 'plot' somewhere above the code you posted (that is where you can specify the dimensions of the image).
If none of this helps, could you post the error message you are seeing?
Thanks for the reply. The error is:
The image "<redacted url="">" cannot be displayed because it contains errors.
My new code is:
$plot=new PHPlot;
$plotarray=findZArray($overall,$meanO,$stddeviationO);
$plot->SetDataType('data-data');
$plot->SetDataValues(findZArray($overall,$meanO,$stddeviationO));
$plot->SetTitle("Standard Deviation of Scores (Overall)");
$plot->SetXTitle('Standard Deviation');
$plot->SetYTitle('Scores');
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->DrawGraph();
Well, no, that error doesn't help. What you are looking for is the error logged by the web server in response to the URL request for the PHP script that draws the plot. (That can be hard to get in some hosting situations, but there just isn't any other place PHP will record the actual errors, if you are using a web server.)
I took your script, added a require_once for phplot.php, replaced your function to get the data with a data array using some of your numbers from above, and I get a good plot. I don't think your function is returning a bad data array - PHPlot really should catch all those cases and tell you about them with an error image. So that leaves something wrong outside of the script.
If you can get to the web server error log, it should clear this up. If not, there are other things we can try.
Thanks again but I'm afraid we are at the "do something else" stage. There is nothing in the httpd error log relating to this script. I don't see how something outside the script can cause the problem as I am not using any global variables so there cannot be any conflict there. I do have a number of functions defined but it would seem like a long shot that one of those conflict and I would think PHP would complain. Anyway it looks like everything is OOP so your function calls would presumably never leave the realm of your class.
Last edit: gw1500se 2014-08-20
This is an FYI to confirm that there is something on my page, outside of PHPlot, that is causing the problem. I commented out my calls and added the sample plot in the distro. It works fine outside my page but fails the same way on my page.
I don't know why PHP error messages aren't showing up in your web server error log, but you might want to run some checks to find out (because it can be very hard to debug anything otherwise).
Back to phplot, here is something you can try. Change the PHP script (the one that makes the PHPlot) to include this line way at the top - before the first code line:
Now point your browser directly to that PHP script - not to the HTML page that references it. (This gets around the issue when the page is accessed through an IMG tag: the browser expects an image and will not display any error text that comes back instead.) You should get either a PHP error, or a plot image.
First, PHP errors are indeed sent to the log, just none for PHPlot. Second, I don't think I understand your instructions. I have always pointed the browser to the PHP script as that is the only way to display any HTML.
Inserting the ini_set command was the first think I tried but the image page with the error is all that I can get.
(Sorry, my mistake. I see now that your error message - "The image cannot be displayed" - would only be seen if the browser pointed right to the image file, not to an HTML wrapper script.)
I duplicated the behavior you are seeing by introducing an error into a PHPlot script. I am getting the exact same browser error, with nothing in my Apache error log. I tried this with both PHP-5.5.15 and PHP-5.4.31, and I don't understand it. It should be logging a "headers already sent" error, because I had my script produce some text output before DrawGraph(), which is a common error. I know I've done this before and had the error logged, but it isn't happening now. Instead, I get only the browser message, because the response is invalid (my text followed by the PNG image data).
I am going to look into this - see if there was some change in PHP or Apache. But in the meantime, please look over your script carefully and make sure you are not generating any output before $plot->DrawGraph(). That means no echo or print, and nothing at all outside of the PHP opening tag (<?php). Even a blank line or a single space at the top of your script before the opening tag will produce this condition.
Sorry, how dumb am I? I forgot I needed to put the PHPlot code into an
tag and was calling the routines directly. Sheesh.
Last edit: gw1500se 2014-08-20
I'm not sure what you mean by "putting the PHPlot into an image". Anyway, this is what I learned about the lack of error message in the case I found.
If the PHP configuration setting output_buffering is set to On or a number (like 4096, as in the supplied sample php.ini files), then the output is buffered, and sending headers works even if out of order. That means if a PHPlot script produces output before DrawGraph() (which sends the Content-Type header), then there is no PHP error logged, and the output - which is not valid, because it has text before the image - is sent to the browser. Not ideal.
If output_buffering is off, which is not recommended, then the same script error will result in an error recorded:
PHP Warning: Cannot modify header information - headers already sent by ...
. This message shows you where in the script the incorrect output came from, which is very helpful.What I meant was that the plot script was set as the src attribute of an image tag. Instead I was calling it inline with the rest of my php code on the page. I needed to separate the plot code into a separate file and then put that file as the source for the image tag. Just being dumb.
Not dumb, but yes it won't work that way. However, there is a way to do it like that - with a single script - if you want, using EncodeImage and the "data URL scheme".
Thanks for pointing that out. That will solve another problem accessing my data which is in a PHP class.
P.S. A small typo in the example code in the documentation. The 'F' in 'false' should be lower case. Also I think the echo should be:
echo "
EncodeImage()."\" />";
Last edit: gw1500se 2014-08-21