我用jpgraph生成了一个折线图,以下代码是可以运行的!
我从newFile.php页面点一个链接到
jpgraphzhe.php页面,但是我在jpgraphzhe.php改变数据后,在从newFile.php点那个链接,图片并没有发生改变,还是第一次加载的图片,必须手动刷新后才能显现。请问各位前辈这个问题如何解决!createGraphPic.php<?php
include ("../jpgraph/jpgraph.php");
include ("../jpgraph/jpgraph_line.php");         //引用折线图LinePlot类文件class GraphPolylines 
{
    var $graph;
    var $p1;
  
    function GraphPolylines()
    {
     unset($this->graph);   
        $this->graph = new Graph(600,300,"auto");         //创建画布
    }
    function setPicTiele($title) //设置标题
    {
        $this->graph->title->Set($title);
    }
    function setTickLabels($xTitle)//设置X轴显示内容
    {
        $this->xTitle = $xTitle;
        
    }
    function setLinePlot($data) //创建折线对象
    {
        $this->p1 = new LinePlot($data);          //创建折线图对象
        $this->p1->->SetType(MARK_FILLEDCIRCLE);      //设置数据坐标点为圆形标记
        $this->p1->->SetFillColor("red");         //设置填充的颜色
        $this->p1->->SetWidth(4);           //设置圆形标记的直径为4像素
        $this->p1->SetColor("blue");           //设置折线颜色为蓝色
    }
    function createPic()//真正画图
    {
        //设置统计图所在画布的位置,左边距50、右边距40、上边距30、下边距40,单位为像素
        $this->graph->img->SetMargin(50,40,30,40);
        $this->graph->img->SetAntiAliasing();
        //设置折线的平滑状态
        $this->graph->SetScale("textlin");
        //设置刻度样式
        $this->graph->SetShadow();           //创建画布阴影        $this->graph->title->SetFont(FF_SIMSUN,FS_BOLD);      //设置标题字体
        $this->graph->SetMarginColor("lightblue");        //设置画布的背景颜色为淡蓝色
        $this->graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);     //设置Y轴标题的字体
        $this->graph->xaxis->SetPos("min");
        $this->graph->yaxis->HideZeroLabel();
        $this->graph->ygrid->SetFill(true,'#[email protected]','#[email protected]');        $this->graph->xaxis->SetFont(FF_SIMSUN);         //设置X坐标轴的字体
        $this->graph->yscale->SetGrace(20);
        if(!!$this->xTitle)
        {
             $this->graph->xaxis->SetTickLabels($this->xTitle);
        }
        $this->graph->Add($this->p1);            //在统计图上绘制折线
        
        $this->fileOperate();
        $this->graph->Stroke("consture.png");            //输出图像
       
    }
    function fileOperate()
{
if(file_exists("consture.png"))
{
unlink("consture.png");
}

}?>
jpgraphzhe.php<?php
include ("createGraphPic.php");$graphPic=new GraphPolylines();
$title="2007年《PHP5从入门到精通》图书月销售额折线图";
$graphPic->setPicTiele($title);
$a=array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");//X轴
$graphPic->setTickLabels($a);
$datay = array(100,30,300,400,50,300,700,800,900,1000,1100,500); 
$graphPic->setLinePlot($datay);
$graphPic->createPic();
?>
<html><head>
<title>jpgraph折线图</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../images/style.css" type="text/css"></head>
<body bgcolor="#FFFFFF">
<br>
<br>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td><img src="consture.png" border=0 alt=<?=$title?>>
</td>
</tr>
</table>
</body>
</html>
newFile.php<html><head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../images/style.css" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<a href="jpgraphzhe.php">jpgraph折线图</a><br><br>
</body>
</html>

解决方案 »

  1.   

    小妹妹要学会查看资料,这是我从它网站上找到的:http://www.aditus.nu/jpgraph/jpgraphfaq.php---2.8 I change my data but my image does not get updated? The old image is still send back to the browser?
    What you are seeing is a cached version of Your image. Depending on your setup it could either be that the browser has a cached image or You are using the builtin cache system in the library by accident.
    Fixing the browser cache
    Since the script from the browser point of view is the same it just displays the old image. To fix this you need to turn of the browser image caching.
    Another "trick" that can be used since normally it is impossible to control the browser for the end user is ot add a "dummy" URL argument which changes. This way the brower will always see a new URL and then alwyas reload that file. This could be done for example as:
    echo ('<img src="graphscript.php?' .microtime(). '">');
    Fixing the library cache
    The other reason might be that You have enabled the built-in cache feature in JpGraph. To turn it of You can either
    Not specify a cache name in the call to Graph(). Just call new Graph(200,200) for example.
    Turn off the reading from the cache by setting READ_CACHE to false (in jpg-config.inc)
    Turn off the reading and writing from the cache by setting USE_CACHE to false (in jpg-config.php)
    Use the cache but with a timeout so that the image will be re-generated if the cached image is older then the specified timeout value in the call to Graph().
      

  2.   

    你....太懒了吧就是说你的图片是缓存了的,
    解决办法是在url上加个随机数,比如microtime()还有它的文件缓存,你把jpg-config.inc里的READ_CACHE设成false就行,看你说手动刷新就看见新数据了,应该是第一种情况
    --------------------------------------------------------------欢迎加入以google wave为交流工具的PHP及web开发讨论组: [email protected] 加入办法:1。 从你的gmail可以直接发信到 [email protected] 2。 PM你的邮箱给我,我直接加入 3。 到http://groups.google.com/group/phpwave/subscribe?note=1申请   如果该网址不能访问请尝试 https://groups.google.com/group/phpwave/subscribe?note=1       或 http://groups.google.co.uk/group/phpwave/subscribe?note=1 ...(或换其它国家域名)