如何在网页中嵌入图形(jpgraph) [英] How to embed a graph (jpgraph) in a web-page

查看:129
本文介绍了如何在网页中嵌入图形(jpgraph)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用脚本, jpgraph本身提供的示例之一.当我将其单独放在网页(空白)上时,它正在绘制图形.但是,当我将代码嵌入到已有的网页(带有某些内容)中时,它并没有绘制图形.

I am using this script which is one of the examples provided by jpgraph itself. When I put this on a web-page (blank) by itself, it's drawing the graph. But when I embed the code in already existing web-page (with some content), it ain't drawing a graph.

GD已根据phpinfo()启用. Iam使用jpgraph 3.5.0b1.

GD is already enabled according to phpinfo(). Iam using jpgraph 3.5.0b1.

推荐答案

问题是您将HTML/文本输出与图像输出混合在一起.

The problem is that you are mixing HTML/text output with image output.

每次使用PHP脚本生成图形内容时,您都必须以不同于普通HTML或文本的方式来处理输出.

Any time you have a PHP script generate graphical content you have to handle the output differently than normal HTML or text.

有几条路线,我将在这里简单介绍.

There are a few routes, I'll cover them briefly here.

将输出保存到文件中,并在HTML中使用该文件名

//replace this line:
// Display the graph
//$graph->Stroke();

// with these lines:

    // Default is PNG so use ".png" as suffix
    $fileName = "/tmp/imagefile.png";
    $graph->img->Stream($fileName);

..然后在图像标签中使用$filename,例如这样:

.. then use $filename in an image tag, like this (for example):

print '<img src="'.$filename.'" />';

创建一个独立的PHP脚本,该脚本将输出图形

您可以单独在名为graph_render_script.php的文件中直接使用示例脚本.然后,在您的HTML中,将该脚本用作源:

You can use the example script as-is, alone in a file called graph_render_script.php. Then, in your HTML, you use that script as a source:

<img src="graph_render_script.php" />

输出base-64编码的数据

另一种方法是使用base-64编码的图像数据.这是相对简单的:

Another route is to use base-64 encoded image data. This is relatively simple to do:

print '<img src="data:image/png;base64,'.base64_encode($graph->Stroke()).'" />';

与往常一样,文档应作为您的指南!

As always, the documentation should be your guide!

文档

  • http://jpgraph.net/download/manuals/chunkhtml/ch05s05.html
  • base64_encode - http://php.net/manual/en/function.base64-encode.php

这篇关于如何在网页中嵌入图形(jpgraph)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆