修改数据可视化中得时间bug,修改提示框中得日期显示格式

This commit is contained in:
Li Jianxuan 2014-06-13 06:00:56 +00:00
parent 2866056ae1
commit 9ad746b0e4
2 changed files with 161 additions and 114 deletions

View File

@ -12,7 +12,14 @@ $this->breadcrumb()->setSeparator(' > ');
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">
<h3><?= $this->info['title'] ?> <small>数据可视化查看</small></h3> <h3><?= $this->info['title'] ?> <small>数据可视化查看</small></h3>
<h4><small>请在需要查看的可视化要素上点击以描绘图表,再次点击可取消显示</small></h4> <h4><small>请在需要查看的可视化要素上点击以描绘图表,再次点击可取消显示,绘制图像前可自主选择图像类型</small></h4>
<div class="btn-group linetypes" data-toggle="buttons-radio">
<button type="button" class="btn active" value="line">折线图</button>
<button type="button" class="btn" value="column">柱状图</button>
</div>
<a class="btn btn-primary control-btn-cls" href="javascript:void(0);">
清除图像
</a>
<hr /> <hr />
<?php $vars = (new \Westdc\Visual\VariableEncoder)->normaldecode($this->data['vars']);?> <?php $vars = (new \Westdc\Visual\VariableEncoder)->normaldecode($this->data['vars']);?>
@ -23,20 +30,31 @@ $this->breadcrumb()->setSeparator(' > ');
<?php } ?> <?php } ?>
</div> </div>
</div>
<div class="row-fluid">
<!-- 页面内容 --> <!-- 页面内容 -->
<div class="span12"> <div class="span12">
<div id="datachart" style="width:100%;height:500px;"></div> <div id="datachart" style="width:100%;height:500px;"></div>
<a class="btn btn-primary control-btn-cls" href="javascript:void(0);">
清除图像
</a>
</div> </div>
<!-- //页面内容 --> <!-- //页面内容 -->
</div> </div>
<script> <script>
_this = {}; _this = {};
_this.linetype = 'line';
$(function() { $(function() {
$('.linetypes button').click(function(e) {
_this.linetype = $(this).val();
});
Highcharts.setOptions({
lang: {
months : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
//months : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
weekdays: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
}
});
$('#datachart').highcharts('StockChart', { $('#datachart').highcharts('StockChart', {
rangeSelector : { rangeSelector : {
@ -48,9 +66,33 @@ $(function() {
enabled : false enabled : false
}, },
xAxis : { xAxis: {
allowDecimals : true type: 'datetime',
} dateTimeLabelFormats: {
second: '%Y-%m-%d<br/>%H:%M:%S',
minute: '%Y-%m-%d<br/>%H:%M',
hour: '%Y-%m-%d<br/>%H:%M',
day: '%Y<br/>%m-%d',
week: '%Y<br/>%m-%d',
month: '%Y-%m',
year: '%Y'
},
},
tooltip : {
formatter: function() {
var s = '<b>'+ Highcharts.dateFormat('%Y-%m-%d %A %H:%M:%S', this.x) +'</b>';
$.each(this.points, function(i, point) {
s += '<br /><span style="color: '+point.series.color+';">' + point.series.name + ': ' + point.y +'</span>';
});
return s;
}
},
}); });
@ -81,7 +123,11 @@ $(function() {
chart.addSeries({ chart.addSeries({
name: seriename, name: seriename,
data: data, data: data,
type : 'column' type : _this.linetype,
dataGrouping: {
enabled: false,
forced: false,
}
}); });
}, },
'timeout': 30000, 'timeout': 30000,
@ -107,4 +153,5 @@ $( document ).ajaxSend(function() {
$( document ).ajaxSend(function() { $( document ).ajaxSend(function() {
$('#loading').css('display','none'); $('#loading').css('display','none');
}); });
</script> </script>

View File

@ -1,106 +1,106 @@
<?php <?php
namespace Westdc\Visual; namespace Westdc\Visual;
class Record class Record
{ {
public $db; public $db;
public $subdataset; public $subdataset;
public $timeFiled = "utctime"; public $timeFiled = "utctime";
private $sql; private $sql;
function __construct($uuid = NULL,$identifier = "") function __construct($uuid = NULL,$identifier = "")
{ {
$this->initDatabase(); $this->initDatabase();
if(!empty($identifier)) if(!empty($identifier))
{ {
$this->subdataset = $identifier; $this->subdataset = $identifier;
} }
if(!empty($uuid) && !empty($identifier)) if(!empty($uuid) && !empty($identifier))
{ {
$this->initVisual($uuid); $this->initVisual($uuid);
} }
} }
public function __invoke() public function __invoke()
{ {
return $this->getData(); return $this->getData();
} }
public function initDatabase() public function initDatabase()
{ {
$config = \Zend_Registry::get('config'); $config = \Zend_Registry::get('config');
$dsn = "pgsql:host={$config->visual_db->hostname};" $dsn = "pgsql:host={$config->visual_db->hostname};"
."port={$config->visual_db->port};" ."port={$config->visual_db->port};"
."dbname={$config->visual_db->database};" ."dbname={$config->visual_db->database};"
."user={$config->visual_db->username};" ."user={$config->visual_db->username};"
."password={$config->visual_db->password}"; ."password={$config->visual_db->password}";
$this->db = new \PDO($dsn); $this->db = new \PDO($dsn);
} }
public function initVisual($uuid) public function initVisual($uuid)
{ {
$visual = new Visual; $visual = new Visual;
$var_data = $visual->getVisualVars($uuid); $var_data = $visual->getVisualVars($uuid);
$this->sql = $this->makeSql($var_data['data'],$this->subdataset); $this->sql = $this->makeSql($var_data['data'],$this->subdataset);
//echo $this->sql;exit(); //echo $this->sql;exit();
} }
public function getSql() public function getSql()
{ {
return $this->sql; return $this->sql;
} }
public function getData() public function getData()
{ {
$rs = $this->db->query($this->sql); $rs = $this->db->query($this->sql);
$data = []; $data = [];
while($row = $rs->fetch(\PDO::FETCH_ASSOC)) while($row = $rs->fetch(\PDO::FETCH_ASSOC))
{ {
$row['utctime'] = $this->utcMsTime(strtotime($row['utctime'])); $row['utctime'] = $this->utcMsTime(strtotime($row['utctime']));
//var_dump($row); //var_dump($row);
$data[] = array( $data[] = array(
$row['utctime'], $row['utctime'],
$row['value'] $row['value']
); );
} }
return $data; return $data;
} }
public function makeSql($table,$fieldValue) public function makeSql($table,$fieldValue)
{ {
$sql = "SELECT $sql = "SELECT
{$this->timeFiled} as utctime , \"$fieldValue\" as value {$this->timeFiled} as utctime , \"$fieldValue\" as value
FROM $table FROM $table
ORDER BY ORDER BY
extract(YEAR from \"{$this->timeFiled}\") ASC, extract(YEAR from \"{$this->timeFiled}\") ASC,
extract(MONTH from \"{$this->timeFiled}\") ASC, extract(MONTH from \"{$this->timeFiled}\") ASC,
extract(DAY from \"{$this->timeFiled}\") ASC, extract(DAY from \"{$this->timeFiled}\") ASC,
extract(HOUR from \"{$this->timeFiled}\") ASC, extract(HOUR from \"{$this->timeFiled}\") ASC,
extract(MINUTE from \"{$this->timeFiled}\") ASC, extract(MINUTE from \"{$this->timeFiled}\") ASC,
extract(SECOND from \"{$this->timeFiled}\") ASC extract(SECOND from \"{$this->timeFiled}\") ASC
"; ";
return $sql; return $sql;
} }
public function utcMsTime($time=''){ public function utcMsTime($time=''){
if(empty($time)) if(empty($time))
return (time()+8*3600)*1000; return (time()+8*3600)*1000;
else else
return $time*1000; return ($time+8*3600)*1000;
} }
} }