简体   繁体   English

未捕获的参考错误:未定义队列

[英]Uncaught Reference Error: queue is not defined

I am getting the error 我收到错误

Uncaught Reference Error: queue is not defined 未捕获的参考错误:未定义队列

but I do not understand why I am getting the error. 但我不明白为什么会收到错误消息。 I am trying to draw a map of the USA using D3 and I am/was using this guide but it does not exactly match with the most modern version of D3. 我正在尝试使用D3绘制美国地图,并且正在/正在使用本指南,但它与D3的最新版本并不完全匹配。 Here is my code/the code from the video: 这是我的代码/视频中的代码:

(function (){

var width = 400;
var height = 300;

var svg = d3.select('#d3mapUS')
        .append("svg")
        .attr("width", width)
        .attr("height", height);

var projection = d3.geoAlbersUsa()
        .scale(1280)
        .translate([width/2, height/2]),
    path = d3.geoPath()
        .projection(projection);

var stateIDMap = d3.map({

});

queue()
    .defer(d3.json, "us.json")
    .await(function (err, US) {
        var states = svg.append("g")
                .attr("class", "states")
                .selectAll("g")
                .data(topojson.feature(US, US.objects.states).features)
                .enter()
                .append("g");

        states.append("path")
                .attr("d", path);
    });
})();

is queue part of a library? 队列是图书馆的一部分吗? I'm assuming if you attached it in the html it would work anyway. 我假设如果您将其附加到html中,它将仍然有效。 Make sure it's before you import your code. 确保在导入代码之前。

but if it's not working or you're worried about compiler errors you can do this: 但是,如果它不起作用,或者您担心编译器错误,可以执行以下操作:

(function (queue) {
....

})(queue);

I do that when I want to use jquery or window in my iife's. 当我想在我的妻子中使用jquery或window时,我这样做。

If you are using D3 v4.x, the correct syntax is d3.queue . 如果您使用的是D3 v4.x,则正确的语法是d3.queue So, it should be: 因此,应为:

d3.queue()
    .defer(d3.json, "us.json")
    .await(function (err, US) {
        var states = svg.append("g")
            .attr("class", "states")
            .selectAll("g")
            .data(topojson.feature(US, US.objects.states).features)
            .enter()
            .append("g");

        states.append("path")
            .attr("d", path);
});

Check the API: https://github.com/d3/d3-queue#queue 检查API: https : //github.com/d3/d3-queue#queue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM