我正在尝试通过datamaps.usa在Electron应用程序中使用D3和Datamaps。它被困在datamaps.usa.min.js文件的一行中,该行调用
this.svg.append("g")
出现错误“无法读取未定义的属性'append'”。
这是js
var map = new Datamap({
element: document.getElementById('counties'),
geographyConfig: {
dataUrl: 'file:///topoJSON/Iowa.topo.json',
highlightFillColor: '#A6CFEB',
},
scope: 'Iowa.geo',
fills: {
defaultFill: '#BBFF33'
},
setProjection: function(element, options) {
var projection, path;
projection = d3.geoAlbers()
.scale(element.offsetWidth)
.translate([element.offsetWidth / 2, element.offsetHeight / 2 ]);
path = d3.geoPath()
.projection( projection );
return {path: path, projection: projection};
}
});
和HTML
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="app.css">
<script>
var d3 = require("d3");
var geo = require("d3-geo");
</script>
<script src="./topojson.v1.min.js"></script>
<script src="./papaparse.min.js"></script>
<script src="./datamaps.usa.min.js"></script>
<script src="./app.js" charset="utf-8"></script>
</head>