将数据库中的信息图形显示
数据库:sqlite,图形引擎:SVGGraph,显示温度、湿度和时间数据:
<?php
require_once './SVGGraph/SVGGraph.php';
$dsn = 'sqlite:pi';
try{
$dbh = new pdo($dsn,$user,$password);
$dbh->beginTransaction();
$sth = $dbh->prepare('SELECT wen,shi,date FROM info order by num desc limit 50');
$sth->execute();
$result = $sth->fetchAll();
$settings=array(
'grid_division_h' => 10,
//'grid_division_v' => 2,
'axis_min_v' => 0,
//'show_axis_text_h'=> false,
//'axis_text_space_h'=>20,
//'axis_text_angle_h'=>20
);
$settings['structured_data'] = true;
$settings['structure'] = array(
'key' => 2,
'value' => array(0,1),
);
$graph = new SVGGraph(1000, 400,$settings);
//print_r($recordlist);
$dsn = null;
}catch (pdoexception $e){
echo 'Connection failed:'.$e->getmessage();
$dsn = null;
}
$graph->Values($result);
$graph->Render('MultiLineGraph');
?>
发表评论