[英]Why is this working in fireFox but not in Chrome or Internet Explorer 9?
[英]Flot graph not working in Firefox or Internet Explorer, only Chrome
我正在使用Flot jQuery插件在我的網站上呈現圖形。 它在最新版本的Chrome中運行良好,但在Firefox和Internet Explorer中似乎失敗了。 我使用的是Firefox 21版和Internet Explorer 10版。 這是相關的代碼:
$(document).ready(function() {
var currentURL = window.location;
// This will hold our plot data
var playersPlots = [];
var pingPlots = [];
// Make an AJAX request to get the server stats
$.get(currentURL + '/stats.json', function(data) {
$.each(data.stats, function(index, value) {
playersPlots.push([new Date(value.ServerStat.created).getTime(), value.ServerStat.players]);
pingPlots.push([new Date(value.ServerStat.created).getTime(), value.ServerStat.ping]);
});
$.plot($('#server-stats'), [{label: 'Players', data: playersPlots}, {label: 'Ping (ms)', data: pingPlots}], {
xaxis: {
mode: 'time',
timeformat: '%I:%M',
'tickSize': [3, "hour"]
}
});
}, 'json');
});
圖表在Chrome下正常呈現(正確):
但是在Firefox和Internet Explorer下是這樣的:
有沒有人之前遇到過這個問題並且知道原因?
還值得一提的是,Firefox和IE都沒有控制台錯誤,他們都在制作AJAX請求並獲取正確的數據,我已經通過查看開發人員工具的網絡選項卡確認了這些數據。
編輯:還值得一說,如果我像這樣硬編碼值:
$.plot($('#server-stats'), [{label: 'Players', data: [[10, 10], [20, 20]]}, {label: 'Ping (ms)', data: [[30, 30], [40, 40]]}], {
它適用於Firefox,IE和Chrome。
這是因為我的日期格式。 默認情況下,MySQL返回DATETIME為YYYY-MM-DD HH:MM:SS
,當需要為YYYY-MM-DDTHH:MM:SS
我也面臨這樣的問題,但在我的情況下,Datetime已經是這樣的“YYYY-MM-DD HH:MM:SS”格式。
“2015-02-26T00:00:00”
但之后它在Firefox和IE上顯示不好。
然后我找到了解決方案,剛剛將“.000Z”添加到日期,並且它的工作找到了我。
for (var i = 0; i < data.length; i++) {
res.push([new Date(data[i].MONTH + '.000Z'), data[i].USEDUNIT]);
}
min: new Date('2015-02-26T00:00:00.000Z'),
max: new Date('2015-03-04T00:00:00.000Z'),
對於min max我也使用了moment.js(),因為getDate()返回5但我需要05。
var minDate = new Date(moment().format('YYYY-MM-DD') + 'T00:00:00.000Z');
minDate.setDate(minDate.getDate() - 7);
var maxDate = new Date(moment().format('YYYY-MM-DD') + 'T00:00:00.000Z');
maxDate.setDate(maxDate.getDate() - 1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.