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

时间:2016-08-09 14:40:48

标签: javascript d3.js d3v4 queue.js

我收到错误

  

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

但我不明白为什么我会收到错误。我正在尝试使用D3绘制美国地图,我正在使用此guide,但它与最现代版本的D3不完全匹配。这是我的代码/视频中的代码:

(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);
    });
})();

2 个答案:

答案 0 :(得分:0)

是库的队列部分吗?我假设如果你将它附加在html中它仍然会工作。在导入代码之前确保它。

但是如果它不起作用或你担心编译器错误,你可以这样做:

(function (queue) {
....

})(queue);

当我想在我的生活中使用jquery或窗口时,我这样做。

答案 1 :(得分:0)

如果您使用的是D3 v4.x,则正确的语法为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); }); 。所以,它应该是:

public partial class Form1 : Form
{
    Graphics G;
    Pen myPen = new Pen(Color.Black);
    Point sp = new Point(0, 0);
    Point ep = new Point(0, 0);
    int ctrl = 0;

    public Form1()
    {
        InitializeComponent();
    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {

    }

    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        sp = e.Location;
        if(e.Button == MouseButtons.Left)
        {
            ctrl = 1;
        }
    }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        ctrl = 0;
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if(ctrl == 1)
        {
            ep = e.Location;
            G = panel1.CreateGraphics();
            G.DrawLine(myPen, sp, ep);
        }
        sp = ep;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        colorDialog1.ShowDialog();
        myPen.Color = colorDialog1.Color;
        colourBtn.BackColor = colorDialog1.Color;
    }

    private void clrBtn_Click(object sender, EventArgs e)
    {
        G.Clear(colorDialog2.Color);
    }

    private void button1_Click_1(object sender, EventArgs e)
    {
        colorDialog2.ShowDialog();
        panel1.BackColor = colorDialog2.Color;
        panel1Colourbtn.BackColor = colorDialog2.Color;

    }

    private void button1_Click_2(object sender, EventArgs e)
    {
        SaveFileDialog dlgSave = new SaveFileDialog();
        dlgSave.Title = "Save Image";
        dlgSave.Filter = "Bitmap Images (*.bmp)|*.bmp|All Files (*.*)|*.*";
        if (dlgSave.ShowDialog(this) == DialogResult.OK)
        {

            using (Bitmap bmp = new Bitmap(panel1.Width, panel1.Height))
            {
               // how do i save my drawing using savefiledialog? 
            }

        }
    }

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