Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript d3格式错误-将v3转换为v4_Javascript_D3.js_Scatter Plot - Fatal编程技术网

Javascript d3格式错误-将v3转换为v4

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

我试图将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, 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前缀的说明符字符串


关于您的编辑;如果你的年份是整数值,你甚至不需要指定记号格式。哦,是的,你是对的。谢谢