-
- DEFINE("CACHE_DIR","/tmp/jpgraph_cache/");'
- DEFINE("TTF_DIR","/usr/X11R6/lib/X11/fonts/truetype/");
Copy code
Windows system changed to:
-
- DEFINE("CACHE_DIR","c:/apache/htdocs/ jpgraph_cache/");
- Notes:
(1) The cache folder path can be defined by yourself, while the TTF (font) folder must be %system%/Fonts.
(2) Make sure that PHP has write permissions on the cache folder.
5.
After completing the above settings, you can use JpGraph. You can first copy the JpGraph example to the htdocs folder and run it to take a look.
Read data from database into jpgraph chart
1,
Copy the file example16.2.php in the ./src/Examples directory and the files jpgraph_bar.php, jpgraph_gradient.php, jpgraph_line.php, jpgraph_plotmark.inc, and jpgraph.php in the ./src directory to the same directory.
2.
Establish database jpg, database table test
Create 2 fields:
id (primary key): int
Number: int
and add some data
3.
Modify example16.2.php
Modified code
include ("jpgraph.php"); include ("jpgraph_line.php"); include ("jpgraph_bar.php"); "root",""); mysql_select_db("jpg",$connect); - $query=mysql_query("select * from test",$connect);
- $i=0; // bbs.it-home. org
- while ($array=mysql_fetch_array($query)) {
- $l2datay[$i]=$array["number"];
- $i++;
- }
- mysql_close($connect);
- // Create the graph.
- $graph = new Graph(400,200,"auto");
- $graph->SetScale("textlin");
- $graph->img->SetMargin(40,130,20,40);
- $graph- >SetShadow();
- // Create the bar plot
- $bplot = new BarPlot($l2datay);
- $bplot->SetFillColor("orange");
- $bplot->SetLegend("Result");
- // Add the plots to t'he graph
- $graph->Add($bplot);
- $graph->title->Set("Adding a line plot to a bar graph v1");
- $ graph->xaxis->title->Set("X-title");
- $graph->yaxis->title->Set("Y-title");
- $graph-> title->SetFont(FF_FONT1,FS_BOLD);
- $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
- $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
- //$graph->xaxis->SetTickLabels($datax);
- //$graph->xaxis->SetTextTickInterval(2);
- // Display the graph
- $graph-> Stroke();
- ?>
-
-
- Copy code
-
-
- Instructions:
The latest version of JpGraph is Version: 3.5.0b1.
-
|