我有一个用于Y轴的数组,我想在图形中显示它们...,并希望每秒钟重新加载该图形...我使用AJAX获取此图形并显示在主页中...
图表代码如下。
function graph1()
{
$dt=array();
$q=mysql_query("select * from pricee ") or die (mysql_error());
while($data=mysql_fetch_object($q))
{
array_push($dt,$data->price);
}
$datay = $dt;
for( $i=0; $i < sizeof($datay); ++$i )
{
$data[$i] = $datay[$i];
}
// Create the new graph
$graph = new Graph(540,300,auto);
// Slightly larger than normal margins at the bottom to have room for
// the x-axis labels
$graph->SetMargin(40,40,30,130);
// Fix the Y-scale to go between [0,100] and use date for the x-axis
$graph->SetScale('datlin',0,max($datay));
// Adjust the start time for an "even" 5 minute, i.e. 5,10,15,20,25, ...
$graph->xaxis->scale->SetTimeAlign(SECADJ_1);
// Force labels to only be displayed every 1 second
$graph->xaxis->scale->ticks->Set(1);
// Use hour:minute format for the labels
$graph->xaxis->scale->SetDateFormat('H:i:s');
$graph->title->Set("Example on Date scale");
// Set the angle for the labels to 90 degrees
$graph->xaxis->SetLabelAngle(90);
$line = new LinePlot($data,$xdata);
$line->SetLegend('Merc Price');
$line->SetFillColor('[email protected]');
$graph->Add($line);
return $graph->Stroke();
}
谢谢朋友
在这里,您可以看到工作示例。相当不错的解决方案http://www.wattnotions.com/making-updating-graph-using-javascript-jpgraph/
主要思想是从“ Rizwan Shamsher Kaim Khani”和官方文档中总结而来的:http://jpgraph.net/download/manuals/chunkhtml/ch05s05.html
如果您非常简化代码,则可以将非常短的js代码放入HTML中。php文件保持原样。
<!DOCTYPE html>
<html>
<body>
<script>
function refresh() {
setInterval(function() {
var image = document.getElementById('myImage');
image.src = "index.php?" + new Date().getTime();
}, 1000);
}
refresh();
</script>
<img id="myImage" src="index.php"/>
</body>
</html>
要实时查看刷新尝试,请将其添加到index.php * /
/* NOTE! $today variable is mandatory usage */
$today = date("Y-m-d H:i:s");
$graph->title->Set('Title'.' '.$today);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句