Google 图表工具示例不起作用

发布于 2024-09-05 21:24:45 字数 1316 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

握住我的手 2024-09-12 21:24:45

替换“内容”=> 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.

橙幽之幻 2024-09-12 21:24:45

这绝对可以工作...我认为上面的例子中存在一些错误..它们在下面得到解决。

<?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);

$query = http_build_query($chart);

$fullurl = $url."?".$query;

$context = stream_context_create(

    array(
            'http' => array(
                    'method' => 'GET',
                    'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
                                "Content-length: 0",

            )
    )
);

$ret = fopen($fullurl, 'r', false, $context);
fpassthru($ret);
?>

This will work Absolutely fine... Some mistakes in the above example i think.. they are solved below.

<?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);

$query = http_build_query($chart);

$fullurl = $url."?".$query;

$context = stream_context_create(

    array(
            'http' => array(
                    'method' => 'GET',
                    'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
                                "Content-length: 0",

            )
    )
);

$ret = fopen($fullurl, 'r', false, $context);
fpassthru($ret);
?>
分開簡單 2024-09-12 21:24:45

这对我有用:

<?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);

$query = http_build_query($chart);

$fullurl = $url."?".$query;

$context = stream_context_create(

    array(
            'http' => array(
                    'method' => 'GET',
                    'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
                                "Content-length: 0",
                    'proxy' => 'tcp://X.X.X.X:XXXX'
            )
    )
);

$ret = fopen(fullurl, 'r', false, $context);
fpassthru($ret);

This works for me:

<?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);

$query = http_build_query($chart);

$fullurl = $url."?".$query;

$context = stream_context_create(

    array(
            'http' => array(
                    'method' => 'GET',
                    'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
                                "Content-length: 0",
                    'proxy' => 'tcp://X.X.X.X:XXXX'
            )
    )
);

$ret = fopen(fullurl, 'r', false, $context);
fpassthru($ret);
踏月而来 2024-09-12 21:24:45

我有同样的问题,我分为

$context = stream_context_create(
array('http' => array(
  'method' => 'POST',
  'content' => http_build_query($chart))));

两个陈述:

$x = array('http' => array(
  'method' => 'POST',
  'content' => http_build_query($chart)));

$context = stream_context_create($x);

这似乎解决了它(请不要问我为什么)

I had the identical problem, and I split

$context = stream_context_create(
array('http' => array(
  'method' => 'POST',
  'content' => http_build_query($chart))));

into two statements:

$x = array('http' => array(
  'method' => 'POST',
  'content' => http_build_query($chart)));

$context = stream_context_create($x);

and that seemed to solve it (please don't ask me why)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文