-
- DEFINE("CACHE_DIR","/tmp/jpgraph_cache/");'
- DEFINE("TTF_DIR","/usr/X11R6/lib/X11/fonts/truetype/");
复制代码
Windows系统改为:
-
- DEFINE("CACHE_DIR","c:/apache/htdocs/ jpgraph_cache/");'
- DEFINE("TTF_DIR","c:/windows/fonts");
复制代码
注意事项:
(1)cache(缓存)文件夹路径可以自己定义,而TTF(字体)文件夹必须是%system%/Fonts。
(2)确保PHP对cache(缓存)文件夹有写的权限。
5、
完成上述设置后就可以使用JpGraph了,可以先将JpGraph的例子copy到htdocs文件夹中,运行一下看看。
从数据库中读取数据到jpgraph图表中
1、
将./src/Examples目录中的文件example16.2.php以及./src目录中的文件jpgraph_bar.php、jpgraph_gradient.php、jpgraph_line.php、jpgraph_plotmark.inc、jpgraph.php拷贝到同一目录下。
2、
建立数据库jpg,数据库表test
建立2个字段:
id(主键):int
number:int
并添加一些数据
3、
修改example16.2.php
修改后的代码
-
- include ("jpgraph.php");
- include ("jpgraph_line.php");
- include ("jpgraph_bar.php");
- $connect=mysql_connect("localhost","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();
- ?>
复制代码
说明:
JpGraph的最新版本为 Version: 3.5.0b1。
|