Javascript d3格式错误-将v3转换为v4
我试图将d3从版本3转换为版本4,但出现以下错误:Javascript d3格式错误-将v3转换为v4,javascript,d3.js,scatter-plot,Javascript,D3.js,Scatter Plot,我试图将d3从版本3转换为版本4,但出现以下错误: Uncaught Error: invalid format: function (d) { var prefix = d3.formatPrefix(d); return prefix.scale(d) + prefix.symbol; } 有人能告诉我怎么解决这个问题吗 var xScale = d3.scaleLinear() .range([0, widt
Uncaught Error: invalid format: function (d) {
var prefix = d3.formatPrefix(d);
return prefix.scale(d) + prefix.symbol;
}
有人能告诉我怎么解决这个问题吗
var xScale = d3.scaleLinear()
.range([0, width])
.domain([2000, 2018])
.domain(d3.extent(countries, function(d) { return d.published_year; }))
//Set new x-axis
var xAxis = d3.axisBottom()
.ticks(10)
.tickFormat(function (d) {
return xScale.tickFormat((mobileScreen ? 4 : 8),function(d) {
var prefix = d3.formatPrefix(d);
return prefix.scale(d) + prefix.symbol;
})(d);
})
.scale(xScale);
//Append the x-axis
wrapper.append("g")
.attr("class", "x axis")
.attr("transform", "translate(" + 0 + "," + height + ")")
.call(xAxis);
更新:
我想在v4 d3中的x轴上显示年份,在John的帮助下,我在一行中完成了这项工作:
var xScale = d3.scaleLinear()
.range([0, width])
.domain([2000, 2018])
.domain(d3.extent(countries, function(d) { return d.published_year; }))
//Set new x-axis
var xAxis = d3.axisBottom()
.ticks(10)
.tickFormat(d3.format(""))
.scale(xScale);
d3.formatPrefix
未按应有的方式调用。它需要一个确定SI前缀的说明符字符串
关于您的编辑;如果你的年份是整数值,你甚至不需要指定记号格式。哦,是的,你是对的。谢谢