cksraj Posted September 10, 2009 Share Posted September 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173767-solved-phplot-graph-not-showing/ Share on other sites More sharing options...
Mark Baker Posted September 10, 2009 Share Posted September 10, 2009 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=... Quote Link to comment https://forums.phpfreaks.com/topic/173767-solved-phplot-graph-not-showing/#findComment-915994 Share on other sites More sharing options...
cksraj Posted September 11, 2009 Author Share Posted September 11, 2009 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? Kindly advice. Thanks Crew Kasy Raj Quote Link to comment https://forums.phpfreaks.com/topic/173767-solved-phplot-graph-not-showing/#findComment-916547 Share on other sites More sharing options...
Mark Baker Posted September 11, 2009 Share Posted September 11, 2009 What would you expect to see if you sent a stream of binary image data directly to a web browser? Quote Link to comment https://forums.phpfreaks.com/topic/173767-solved-phplot-graph-not-showing/#findComment-916551 Share on other sites More sharing options...
cksraj Posted September 11, 2009 Author Share Posted September 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173767-solved-phplot-graph-not-showing/#findComment-916569 Share on other sites More sharing options...
Mark Baker Posted September 11, 2009 Share Posted September 11, 2009 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="... Quote Link to comment https://forums.phpfreaks.com/topic/173767-solved-phplot-graph-not-showing/#findComment-916571 Share on other sites More sharing options...
cksraj Posted September 15, 2009 Author Share Posted September 15, 2009 Thanks for your detailed reply. I got it clearly. Quote Link to comment https://forums.phpfreaks.com/topic/173767-solved-phplot-graph-not-showing/#findComment-918803 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.