Closed GoogleCodeExporter closed 9 years ago
I have PHP Version 5.2.9
Original comment by pankaj.k...@gmail.com
on 17 Jun 2010 at 12:38
Hello,
Thank you for you bug report, and sorry about that, it's still a development
version that hasn't been extensively tested.
Try to access to :
http://localhost/googlechart/examples/pie_chart.php?debug=true
It should displays debug info, and an error message if any. Can you copy/paste
this?
Thanks
Original comment by remi.lan...@gmail.com
on 17 Jun 2010 at 12:59
Thanks remi for replying i am getting this message while accessing
http://localhost/googlechart/examples/pie_chart.php?debug=true as suggested by
you.
array(4) { ["cht"]=> string(2) "pc" ["chs"]=> string(7) "500x200" ["chd"]=>
string(16) "t:10,20,30|50,50" ["chl"]=> string(10) "|||Foo|Bar" }
Warning: file_get_contents(http://chart.apis.google.com/chart)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 400 Bad Request in E:\xampp\htdocs\googlechart\lib\GoogleChartApi.php
on line 220
But strangely the pie chart also loads with it when i added ?debug=true.
I am also attaching the screen shot.
Original comment by pankaj.k...@gmail.com
on 18 Jun 2010 at 5:51
Attachments:
Ok I suspect an issue with your PHP setup, because if the chart displays
correctly in debug mode, it means that the URL is a valid query.
Can you please try to switch to GET method, and tell me the result? Add:
{{{
$chart->setQueryMethod(GoogleChartApi::GET);
}}}
before rendering the chart (for example, just before the `if (
isset($_GET['debug']) )`). Does it work now?
Can you also tell me if you're using a prepackaged Apache/PHP like EasyPHP or
WAMP? So that I can install it and test myself.
Thanks
Original comment by remi.lan...@gmail.com
on 18 Jun 2010 at 6:49
Thanks remi i have added the $chart->setQueryMethod(GoogleChartApi::GET); as
suggested by you and it works now without ?debug=true.
Can you please tell me what was the real issue?
I am using XAMPP for Windows Version 1.7.1
Original comment by pankaj.k...@gmail.com
on 18 Jun 2010 at 7:34
Ok, glad to hear that it works now. Google Chart API can work with GET or POST
requests. GET requests are simpler, but are limited to 2K characters. That's
why I've decided to use POST by default (limited to 16k character) for the
library, even though the PHP code for creating a post request is slightly more
complex.
So based on what you tell me, it appears that there is a bug with POST requests
code in some environments, but I don't know yet to what it is related (Apache
config, PHP config, or maybe Windows ?). I'll install XAMPP and see if I can
reproduce the bug.
In the meanwhile, you can safely use GET requests, or generate the URL and use
it in a img tag (getUrl() and toHtml() methods).
Original comment by remi.lan...@gmail.com
on 18 Jun 2010 at 8:19
It indeed doesn't work with XAMPP. However examples are working fine with WAMP
Server 2, so I guess this issue is not related to Windows itself but to some
configuration.
Original comment by remi.lan...@gmail.com
on 18 Jun 2010 at 9:23
This issue was closed by revision r44.
Original comment by remi.lan...@gmail.com
on 18 Jun 2010 at 9:45
[deleted comment]
Thanks remi made the changes as suggested in revision r44(removed the
$chart->setQueryMethod(GoogleChartApi::GET);)) now the post method is also
working.
Original comment by pankaj.k...@gmail.com
on 18 Jun 2010 at 10:57
The POST query is built using PHP function http_build_query(). This function
basically implode an array with the value of "arg_separator.output" as
separator (or the "arg separator" argument of the function, if specified). This
value is "&" by default in almost every PHP distribution I have seen. However,
for some reason, XAMPP comes with "&" as default value for
"arg_separator.output". Hence, the POST query looks like, for example,
"cht=pc&chs=500x200", which is interpreted as "parameter 'cht' is 'pc' and
parameter 'amp;chs' is '500x200'" by Google Chart API. So the parameters name
(except the first one) are wrong and it returns an HTTP 400 Bad request.
I assume this change in the php.ini has been made by XAMPP team to
automatically HTML-encode the result of http_build_query as "&" must be written
"&" in HTML in order to pass W3C validation. However I think this is a bad
choice because:
1) echoing the result in an HTML document is not the only way to use
http_build_query (you could want to output plain text, JSON, or use the result
for POST query for example)
2) if you want to escape the script for HTML, the same result could be achieved
by wrapping whatever you want to display with "htmlentities()"
Besides, a similar mechanism already exists in Google Chart PHP Library: the
first parameter of getUrl() is a boolean (default true), that indicate whether
you want to escape the "&" for HTML or not. And that's why it worked with GET
method btw.
In r44 I enforced the "arg separator" argument, so now the lib is independent
from the PHP config file.
Original comment by remi.lan...@gmail.com
on 18 Jun 2010 at 11:00
Original issue reported on code.google.com by
pankaj.k...@gmail.com
on 17 Jun 2010 at 12:28