开发者

How to add graph to website?

I'm a beginner here and need help. I have this code, which works and outputs a graph in my browser (if this is the only code in php file). I don't know how to add text below or above just like any other site. When I try, it returns my whole code in the browser. How do I go on about this?

<?php 
  // content="text/plain; charset=utf-8"
  require_once ('jpgraph/src/jpgraph.php');
  require_once ('jpgraph/src/jpgraph_line.php');
  // Some data
  $ydata = array(11,3,8,12,5,1,9,8,5,7);
  // Create the graph. These two calls are always required
  $graph = new Graph(350,250);
  $graph->SetScale('te开发者_开发百科xtlin');
  // Create the linear plot
  $lineplot=new LinePlot($ydata);
  $lineplot->SetColor('blue');
  // Add the plot to the graph
  $graph->Add($lineplot);
  // Display the graph
  $graph->Stroke();
?>

Thanks in advance!


What you need is quite simply:

<img src="graph.php">

Put that in a separate HTML file or PHP script. You cannot output the image and text in the same script / web page. It needs to be separated.

Don't worry about the .php extension for the image src= attribute. It will display despite the lack of .jpeg extension. (The Graph class already outputs the correct MIME type I assume.)


I'm a bit rusty on PHP, but I believe that all "require" are supposed to be made before any content is output. Otherwise, the normal HTML/XHTML syntax and formatting take precedence.


I haven't actually used this library, but I'm assuming the image is output directly to the browser. It's probably easiest to create a new HTML document (or whatever the rest of your site is powered by) and include this as an image, with the image's src being the name of this script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜