Google 图表工具示例不起作用
我正在使用 http://code.google 上给出的 php post 请求示例。 com/apis/chart/docs/post_requests.html 用于生成图表。
代码: Chartserver-image.php
<?php
// Create some random text-encoded data for a line chart.
header('content-type: image/png');
$url = 'http://chart.apis.google.com/chart';
$chd = 't:';
for ($i = 0; $i < 150; ++$i) {
$data = rand(0, 100000);
$chd .= $data . ',';
}
$chd = substr($chd, 0, -1);
// Add data, chart type, chart size, and scale to params.
$chart = array(
'cht' => 'lc',
'chs' => '600x200',
'chds' => '0,100000',
'chd' => $chd);
// Send the request, and print out the returned bytes.
$context = stream_context_create(
array('http' => array(
'method' => 'POST',
'content' => http_build_query($chart))));
fpassthru(fopen($url, 'r', false, $context));
?>
another_page.html
<img width='600' height='200' src='chartserver-image.php'>
现在,当我访问 another_page.html 时,当我单击查看图像时,图像不会加载,它显示
图像“http://localhost/demo/chartserver-image.php” 无法显示,因为它包含错误。
我无法理解的问题是什么?
请帮我解决这个问题,
谢谢
I am using the php post request example given on http://code.google.com/apis/chart/docs/post_requests.html for generating chart.
The code:
chartserver-image.php
<?php
// Create some random text-encoded data for a line chart.
header('content-type: image/png');
$url = 'http://chart.apis.google.com/chart';
$chd = 't:';
for ($i = 0; $i < 150; ++$i) {
$data = rand(0, 100000);
$chd .= $data . ',';
}
$chd = substr($chd, 0, -1);
// Add data, chart type, chart size, and scale to params.
$chart = array(
'cht' => 'lc',
'chs' => '600x200',
'chds' => '0,100000',
'chd' => $chd);
// Send the request, and print out the returned bytes.
$context = stream_context_create(
array('http' => array(
'method' => 'POST',
'content' => http_build_query($chart))));
fpassthru(fopen($url, 'r', false, $context));
?>
another_page.html
<img width='600' height='200' src='chartserver-image.php'>
Right now when i access another_page.html, the image doesn't load when i click on view image it shows
The image “http://localhost/demo/chartserver-image.php” cannot be displayed, because it contains errors.
What is the issue i am unable to understand?
Please help me on this
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
替换“内容”=> http_build_query($chart))));与 '内容' => http_build_query($chart,'', '&'))));解决问题。
我添加了 arg 分隔符 '&'到 http_build_query() ,如果以下情况可以避免错误
arg_separator.output参数在php.ini中修改。
当我检查 phpinfo 时,arg_separator.output 是 &。这导致了问题,所以添加“&” http_build_query() 解决了该问题。
Replacing 'content' => http_build_query($chart)))); with 'content' => http_build_query($chart,'', '&')))); resolves the issue.
I have added arg separator '&' to http_build_query() which avoid bug if the
arg_separator.output parameter is modified in php.ini.
When i checked phpinfo the arg_separator.output was &. That was causing issue so adding '&' to http_build_query() resolves the problem.
这绝对可以工作...我认为上面的例子中存在一些错误..它们在下面得到解决。
This will work Absolutely fine... Some mistakes in the above example i think.. they are solved below.
这对我有用:
This works for me:
我有同样的问题,我分为
两个陈述:
这似乎解决了它(请不要问我为什么)
I had the identical problem, and I split
into two statements:
and that seemed to solve it (please don't ask me why)