Skip to content
Advertisement

JpGraph php graph library – trouble embedding graph

I have managed to create a graph using JpGraph, I want to now take it a step further and embed this graph in my template/view php file.

So I put the graph code into a seperate php file to then embed however, when I try to embed it via <embed src="templates/ctl008/graphshow.php" height=80em; width=160em;> </embed> it leaves me with a requested URL not found error.

I have fiddled with the path and tried just: graphshow.php, ctl008/graphshow.php and other such variations. Is it my path that is not correct or is there something else I am missing? I have also tried to embed it with <img src="graphshow.php" /> .

A funny quirk is when I turn on ini_set('display_errors', 1); error_reporting(E_ALL); and try to view the graph on its own I am left with an error message: JpGraph Error: HTTP headers have already been sent. Caused by output from file gd_image.inc.php at line 92. but if i turn off the error_reporting it displays the graph as expected.

I would appreciate any pointers in the right direction with this 🙂

Here is my graphshow.php file:

JavaScript

Advertisement

Answer

I’d like to start off with a few helpful links:
JpGraph Error: HTTP headers have already been sent
http://www.digialliance.com/docs/jpgraph/html/2210intro.html
https://coursesweb.net/php-mysql/jpgraph-graph-charts-plots-php
https://jpgraph.net/download/manuals/chunkhtml/ch05s05.html

now that that is out of the way, how I managed to get it working:

Starting with the advice/help in the above StackOverflow link I turned my seperate php file into a function the final line of my graphshow.php function was this: $graph->Stroke("charts/graphEnergy.png"); where charts is the folder I am saving in and graphEnergy.png is the name of the file being saved.

then in my view/template page I require_once('chart/ctl008/graphshow.php'); made my php file accessible, called my function like so generateGraph($gasArray, $stromArray, $olArray);

and then in the html section embedded the graph with <img src="./charts/graphEnergy.png" />

What really tripped me up was needing to call the graph.png with the ./ before the charts/graphEnergy.php, and then I was able to display my bootiful graph on my view/template page.

I hope this helps someone in the future 🙂

  • BoogaBooga
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement