当前位置: 移动技术网 > IT编程>开发语言>PHP > Ajax+Jpgraph实现的动态折线图功能示例

Ajax+Jpgraph实现的动态折线图功能示例

2019年05月28日  | 移动技术网IT编程  | 我要评论

三年级日记大全,索朗扎西 兄弟情,太上道德天尊

本文实例讲述了ajax+jpgraph实现的动态折线图功能。分享给大家供大家参考,具体如下:

一 代码

fun.js:

var i=1;
function progress(){
  setinterval("beginprogress()", 600);
}
function beginprogress(){
 $("#img").attr("src", "img.php?m="+i);
 i++;
 if(i>=12){
   i=1;
 }
}

index.php:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>ajax+jpgraph制作动态折线图</title>
</head>
<script language="javascript" src="js/jquery-1.3.2.js"></script>
<script language="javascript" src="js/fun.js"></script>
<body>
  <img id="img" src="img.php?m=0" />
 <br>
 <input type="button" value="开始" onclick="progress()"/>
</body>
</html>

img.php:

<?php
require_once 'src/jpgraph.php';   //导入jpgraph类库
require_once 'src/jpgraph_line.php';   //导入jpgraph类库的柱状图功能
$datatmp = array(56, 78, 34, 65, 89, 24 ,67 ,88, 45, 68, 70, 50);   //设置统计数据
$data1 = array(0, 0, 0, 0, 0, 0 ,0 ,0, 0, 0, 0, 0);   //设置统计数据
$m = $_get['m'];
for($i=0; $i<$m; $i++){
  $data1[$i] = $datatmp[$i];
}
$graph = new graph(500, 320);
$graph->setscale("textlin");
$graph->setshadow();
$graph->img->setmargin(40, 30, 30, 70);
$graph->title->set("图书销售走势表");
$lineplot1 = new lineplot($data1);
$graph->add($lineplot1);
$graph->xaxis->title->set("月份");
$graph->yaxis->title->set("book a销售金额(万元)");
$graph->title->setfont(ff_simsun, fs_bold);
$graph->yaxis->title->setfont(ff_simsun, fs_bold);
$graph->xaxis->title->setfont(ff_simsun, fs_bold);
$lineplot1->setcolor('red');
$lineplot1->setlegend('book a');
$graph->legend->setlayout(legend_hor);
$graph->legend->pos(0.4, 0.95, 'center', 'bottom');
$graph->stroke();

二 运行结果

更多关于php相关内容感兴趣的读者可查看本站专题:《php+ajax技巧与应用小结》、《php网络编程技巧总结》、《php基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家php程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网