【发布时间】:2014-11-15 11:04:13
【问题描述】:
我在高位图上绘制了股市数据:
我的 JS 代码:
$(function() {
$.getJSON('data.php', function(data) {
console.log(data);
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector:{
enabled:false
},
navigator: {
enabled: true
},
useUTC: false,
xAxis: {
type: 'datetime',
labels: {
formatter: function () {
return Highcharts.dateFormat('%H:%M', this.value);
},
}
},
title : {
text : 'NSE Stock Price'
},
credits: {
enabled : false
},
series : [{
name : 'NSE Stock Prices',
data : data,
tooltip: {
valueDecimals: 2
}
}]
});
});
});
我的 JSON 输出(部分):
[["09:01:00",27966.96],["09:03:00",27934.64],["09:03:00",27934.64],["09:07:00",27952.66],["09:07:00",27952.66],["09:07:00",27952.66]]
我预计 x 轴上的时间是上午 9:00 到下午 4:00,但我就是不明白。
我尝试将时间更改为 unix 时间更改日期格式 useUTC 为 true,但没有成功。
更新:
也试过这种格式,
[["2014-11-14 09:01:00",27966.96],["2014-11-14 09:03:00",27934.64],["2014-11-14 09:03:00 ",27934.64]]
更新 2
我的 PHP 代码,
$array_item[] = array(date('H:i:s',strtotime($price_date)), (float)$last_traded_price);
更新 3:(一些最新值)
[["2014-11-17 09:00:00",28065.72],["2014-11-17 09:02:00",28048.8],["2014-11-17 09:04:00",28041.93],["2014-11-17 09:06:00",28029.58],["2014-11-17 09:08:00",28018.68],["2014-11-17 09:10:00",28018.68],["2014-11-17 09:12:00",28018.68],["2014-11-17 09:14:00",28018.68],["2014-11-17 09:16:00",27988.73],["2014-11-17 09:18:00",28001.06],["2014-11-17 09:20:00",28003.06],["2014-11-17 09:22:00",27988.44],["2014-11-17 09:24:00",28011.67],["2014-11-17 09:26:00",27988.56],["2014-11-17 09:28:00",27991.17],["2014-11-17 09:30:00",27983.98],["2014-11-17 09:32:00",27972.01],["2014-11-17 09:34:00",27980.87],["2014-11-17 09:36:00",27994.42],["2014-11-17 09:38:00",28007.38],["2014-11-17 09:40:00",28005.57],["2014-11-17 09:42:00",27986.39],["2014-11-17 09:44:00",28010.79],["2014-11-17 09:46:00",27998.44],["2014-11-17 09:48:00",28012.66]]
这是根据:$array_item[] = array(strtotime($price_date), (float)$last_traded_price);
[[1416195000,28065.72],[1416195120,28048.8],[1416195240,28041.93],[1416195360,28029.58],[1416195480,28018.68],[1416195600,28018.68],[1416195720,28018.68],[1416195840,28018.68],[1416195960,27988.73],[1416196080,28001.06],[1416196200,28003.06],[1416196320,27988.44],[1416196440,28011.67],[1416196560,27988.56],[1416196680,27991.17],[1416196800,27983.98],[1416196920,27972.01],[1416197040,27980.87],[1416197160,27994.42],[1416197280,28007.38],[1416197400,28005.57],[1416197520,27986.39],[1416197640,28010.79],[1416197760,27998.44],[1416197880,28012.66],[1416198000,28018.49],[1416198120,28010.15],[1416198240,28028.18],[1416198360,28035.61],[1416198480,28024.87],[1416198600,28018.95],[1416198720,28007.81],[1416198840,28001.57],[1416198960,28006.85],[1416199080,27997.68],[1416199200,27993.06]]
输出:尽管没有像以前那样给出 00:00,但仍然没有给出完美的时间安排。
图表在中间断裂。
更新 3:
PHP 代码,
while ($stocks_bse_price->fetch())
{
$array_item[] = array(strtotime($price_date)*1000, (float)$last_traded_price);
}
JSFidle 链接:http://jsfiddle.net/Ywr3L/38/
更新 4:
刚刚意识到如果将一整天的数字作为数组的输入给出它会出错。
我已经存储了一整天的数据http://pastebin.com/NVAD5EyG
更新 5:
这是我在 MySql 查询中所做的:
DATE_FORMAT(price_date,'%d-%c-%Y %r') as price_date
然后在 PHP 中
$price_date = $price_date.' UTC';
$array_item[] = array(strtotime($price_date)*1000, (float)$last_traded_price);
这是给我的:
http://jsfiddle.net/rof96xuo/1/
[[1416301200000,28177.51],[1416301320000,28180.46],[1416301440000,28181.03],[1416301560000,28198.98],[1416301680000,28209.03],[1416301800000,28209.03]]
new Date(1416301200000)
Tue Nov 18 2014 14:30:00 GMT+0530 (India Standard Time)
【问题讨论】:
-
您的系列数据不是日期时间,只有时间..
-
老兄,在你的数据中,有一点你有
[1416199920000, 27983.64], [1416200040000, 27976.16],,另一方面你有[1416209280000, 27963.21],[1416166200000, 27961.47],。这没有排序!!再次检查。而且你有很多这样的:[1416177000000, 28177.88] -
1416199920000小于1416200040000并且它之前出现过。1416209280000比1416166200000大,而且之前也出现过。所以你可以看到你没有把你的datetimes 整理好。有的下降,有的上升。 -
您的第一个
datetime是1416281400000,即Nov 18, 3:30!!您的最后一个datetime是1416295440000,即Nov 18, 7:24!!完全如图表所示。更正你的数据,不要说我不这么认为,检查! -
Iran。好的,这解释了它。但是,在这个jsfiddle.net/Ywr3L/38 中再次排序不正确。
标签: php jquery json highcharts highstock