Search code examples
phpgraphjpgraph

Printing data on the side after generating a graph using JGraph library in PHP


Hello I need to generate a report which would include both data and a graph image which is a pictorial representation of the data printed. Now the problem is, the function "stroke" in jpgraph generates the graph, so I get an error if I try to echo any information before the stroke function, and nothing prints onto the browser after the stroke function is executed. Do anybody know a way around for this problem??

Is there any other method to generate a report which has both the graph and tabular data.


Solution

  • JPGraph's Stroke() function will create the graph for you, but you can also pass a filename into the function. This will save the graph as an image which you can then load onto your report, and also output other data around it. For example:

    // build graph code....
    $graph->Stroke('mygraph.png');
    
    echo "<img src='mygraph.png' alt='my graph' />";
    echo "Anything I want to go with the graph";