D3不处理Defer命令

时间:2018-07-29 20:31:18

标签: d3.js

我的javascript文件中出现以下错误:“未捕获的TypeError:无法读取未定义的属性'defer'”我是一个尝试解决类分配问题的新手。感谢您可以为我解决代码问题提供的任何帮助,以及如何更好地在此论坛上发布以获得帮助。这是我的代码。非常感谢。

贾琳

//begin script when window loads

对此注释下面的命令也不满意。

window.onload = setMap();

//set up choropleth map
function setMap() {

//map frame dimensions
 var width = 960,
 height = 460;

//create new svg container for the map
 var map = d3.select("body")
 .append("svg")
 .attr("class", "map")
 .attr("width", width)
 .attr("height", height);

 //create Albers equal area conic projection centered on France
 var projection = d3.geoAlbers()
     .center([0, 46.2])
     .rotate([-2, 0, 0])
     .parallels([43, 62])
     .scale(2500)
     .translate([width / 2, height / 2]);

 var path = d3.geoPath()
     .projection(projection);

从这里开始标记错误代码。

 //use queue to parallelize asynchronous data loading
 d3.queue
   .defer(d3.csv, "data/US_Export.csv") //load attributes from csv
   .defer(d3.json, "data/United_States_Export.topojson") //load spatial data
   .await(callback);

 function callback(error, csvData, United_States){
    console.log(error);
    console.log(csvData);
    console.log(United_States);
   } ;
} ;

function callback(error, csvData, United_States){
//translate United States TopoJSON
var United_States_Export = topojson.feature(United_States, United_States.objects.United_States_Export)

//examine the results
console.log(United_States)

var states = map.append("path")
.datum(United_States)
.attr("class","states")
.attr("d", path);



   };
     var garticule = d3. geoGraticule()
    .step([5, 5]); //place graticule lines every 5 degrees

//create graticule lines
var gratLines = map.selectAll(".gratLines") // select graticule elements that 
will be created
    .data(graticule.lines()) //bind graticule lines to each element to be created
    .enter() //creat an element for each datum
    .append("path") //append each element to the svg as a path element
    .attr("class", "gratLines") //assign class for styling
.attr("d", path); //project graticule lines

//create graticule background
var gratBackground = map.append("path")
    .datum(graticule.outline) //bind graticule background
    .attr("class", "gratBackground") //assign class for styling
    .attr("d", path) //project graticule

//Example 2.6 line 5...creat graticule lines
var gratLines = map.selectAll(".gratLines")

0 个答案:

没有答案