d3js Text Transitioin - 1个示例代码不起作用 [英] d3js Text Transitioin - 1 example code not working
问题描述
我是d3.js的新手,并尝试执行d3示例中给出的一些示例代码。我尝试复制Text Transition-1(链接)示例代码。但是在控制台中遇到了这个错误
I am new to d3.js and trying to execute some of the example codes given in the d3 examples. I tried copying the Text Transition-1 (link) example code. But came across this error in the console
text-transition.html:26 Uncaught TypeError:
d3.select(.. 。)。transition(...)。duration(...)。on不是函数
text-transition.html:26 Uncaught TypeError: d3.select(...).transition(...).duration(...).on is not a function
这是代码我执行:
<!DOCTYPE html>
<html>
<head>
<title>Text Transition animation 1</title>
<meta charset="utf-8">
<style>
h1 {
font: 400 120px/500px "Helvetica Neue";
text-align: center;
width: 960px;
height: 500px;
margin: 0;
}
</style>
<script type="text/javascript" src="d3/d3.min.js"></script>
</head>
<body>
<h1>0</h1>
<script type="text/javascript">
console.log("the script is executing")
var format = d3.format(",d");
d3.select("h1")
.transition()
.duration(2500)
.on("start", function repeat() {
d3.active(this)
.tween("text", function() {
var that = d3.select(this),
i = d3.interpolateNumber(that.text().replace(/,/g, ""), Math.random() * 1e6);
return function(t) { that.text(format(i(t))); };
})
.transition()
.delay(1500)
.on("start", repeat);
});
</script>
</body>
</html>
我使用的d3js版本是3.5.17。在Google Chrome浏览器上执行代码段。提前致谢
The d3js version I am using is 3.5.17. Executing the snippet on Google chrome browser. Thanks in advance
推荐答案
问题似乎与d3版本有关。
The problem is seems to be with the d3 version.
尝试使用< script src =// d3js.org/d3.v4.0.0-alpha.23.min.js\"></script>$c$ c>。
来源: http://d3js.org/d3.v4.0.0-alpha.23.min.js
console.log("the script is executing")
var format = d3.format(",d");
d3.select("h1")
.transition()
.duration(2500)
.on("start", function repeat() {
d3.active(this)
.tween("text", function() {
var that = d3.select(this),
i = d3.interpolateNumber(that.text().replace(/,/g, ""), Math.random() * 1e6);
return function(t) {
that.text(format(i(t)));
};
})
.transition()
.delay(1500)
.on("start", repeat);
});
h1 {
font: 400 120px/500px"Helvetica Neue";
text-align: center;
width: 960px;
height: 500px;
margin: 0;
}
<script src="//d3js.org/d3.v4.0.0-alpha.23.min.js"></script>
<h1>0</h1>
这篇关于d3js Text Transitioin - 1个示例代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!