Jump to content

Archived

This topic is now archived and is closed to further replies.

cksraj

[SOLVED] PHPlot Graph Not Showing

Recommended Posts

Hi all,

 

I have PHP Version 5.2.8 with GD extended. I have installed PHPlot-5.0.6

(copied the files into directory called phplot)

 

gd

GD Support enabled

GD Version bundled (2.0.34 compatible)

FreeType Support enabled

FreeType Linkage with freetype

FreeType Version 2.1.9

T1Lib Support enabled

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

 

After installation I am trying to run very simple phplot script, but it is showing the binary output.

But when I placed the code in separate file namely Graph.php and referred in image tag, it is working fine. (<IMG SRC="<?= $URL ?>Graph.php">)

Please advice what could be wrong in my side!!!

 

------------------

PHP Lot Code

------------------

<?

include("phplot/phplot.php");

$data = array(array('', 10), array('', 1));

$plot = new PHPlot();

$plot->SetDataValues($data);

$plot->SetTitle('First Test Plot');

$plot->DrawGraph();

?>

 

THANKS

Crew Kasy Raj

 

 

Share this post


Link to post
Share on other sites

Correct, the library is generating a binary file, an image file, which can't be displayed directly by the browser. The browser expects straight text, specifically html markup.

That's the whole purpose of <img src=...

Share this post


Link to post
Share on other sites

Hi Mark

 

Thanks for your reply.

 

I understand the purpose of IMG tag. But I am getting this problem only when I try to run in my application. If I run this same code outside my application it is working fine (plotting the graph). Is it a rendering problem? :o

 

Kindly advice.

 

Thanks

Crew Kasy Raj

Share this post


Link to post
Share on other sites

What would you expect to see if you sent a stream of binary image data directly to a web browser?

Share this post


Link to post
Share on other sites

Ok let me tell you clearly. I have apache webser and I ran graph.php directly from my web browser. It is showing the graph. When I move the same code to a function and calling from particular place of my application then it is showing binary output.

 

Why it is happening? What am I missing?

 

THanks,

Crew Kasy Raj

Share this post


Link to post
Share on other sites

If you want to send the image data directly to the browser, then you need to send the appropriate http header to advise the browser that it's about to receive a stream of binary data that should be treated as an image (PNG, JPG, GIF or whatever). These headings apply to the entire browser page, and default to HTML.

 

When you run graph.php directly, is clearly sending the necessary headers, so it displays correctly

 

When you run it from within a particular place in your application, you have already started rendering html in the page, or have (at the very least) send the http headers to advise the browser that it is about to receive html rather than image data

If your application is trying to embed the chart directly within normal html markup, then it will display binary data... the browser is already rendering the page as html, not as an image of any type

The way to embed an image within your html markup is using <img src="...

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.