javascript - 为什么 d3 日期轴在 Firefox 中对于某些特定日期域失败?

标签 javascript firefox d3.js

我使用的是 Windows 10、Chrome 53.0.2785.116 m(64 位)、Firefox 49.0.1 和 d3 v. 4.2.6。下面的代码在 Chrome 中运行良好:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.js"></script>
</head>
<body>
<div id="chart"></div>
<script type="text/javascript">
var dates = ["2015-10-11","2015-10-14","2015-10-15","2015-10-16","2015-10-19"];
var w = 600;
var parseDate = d3.timeParse("%Y-%m-%d");
dates.forEach(function(d,i) {dates[i]=parseDate(d)});
console.log(dates);
var svg = d3.select("#chart").append("svg").attr("width", w);
var x = d3.scaleTime().range([0, 500]).domain(d3.extent(dates, function(d) { return d; }));
var xAxis = d3.axisBottom(x);
svg.append("g").attr("transform", "translate(50,50)").call(xAxis);
</script>        
</body>
</html>

但在 Firefox 中失败,并在控制台中留下此消息:

Error: Script terminated by timeout at:
newInterval/interval.range@d3.v4.js:5094:8
calendar/scale.ticks@d3.v4.js:7018:13
axis@d3.v4.js:8888:54
selection_call@d3.v4.js:7615:3
@file:///C:/test/test.html:18:1

此外,如果我将第一个日期更改为“2015-10-12”,那么它将在两种浏览器中工作。 我在 d3.v4.js 中的这些行中查找了一些答案,但没有结果。我不是 javascript 黑带,所以我可能错过了一些东西。 我也在互联网上搜索过,但没有找到对这种奇怪行为的解释。 有人有任何线索吗?

编辑:在运行 Ubuntu 16.04 的虚拟机中测试并获得完全相同的结果。在 Chrome 中工作正常,但在 Ubuntu canonical 1.0 的 Mozilla Firefox 中脚本因超时错误而终止。

最佳答案

感谢 d3 的 Mike Bostock 以及他使用 d3.utcParse 和 d3.scaleUtc 的建议,现在 Firefox 可以按预期工作了!

关于javascript - 为什么 d3 日期轴在 Firefox 中对于某些特定日期域失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39738671/

相关文章:

javascript - 尝试对齐视频时的典型 IE 问题 - 请指教

javascript - 如何在数字组之间设置 math.random

javascript - nvd3 piechart.js - 如何编辑工具提示?

javascript - D3 TSV 列访问

asp.net - 在回发上保持滚动位置不适用于 Firefox

D3.js:我可以从刻度线偏移刻度标签吗?

javascript - 从 JavaScript 调用 PHP 文件是否安全?

javascript - AngularJS 绑定(bind) Ng-Model Inside 指令具有错误的属性名称

javascript - 在 Firefox 16.0.1 中启动 fancybox 时页面布局中断

css - Extjs 3.x : Default theme color in tabpanel tabs instead of white