我是新來的d3.js。我想從頭開始創建這個地區分佈圖:使用d3.js的Choropleth地圖
我的劇本沒有顯示任何錯誤,並在元素標籤,我可以看到數據,但沒有顯示在屏幕上。我已閱讀多份文件,但仍不知道我錯過了什麼。
的jsfiddle: https://jsfiddle.net/jx3hjfgw
var width = 960,
height = 1160;
// SVG element as a JavaScript object that we can manipulate later
var svg = d3.select("#map").append("svg")
.attr("width", width)
.attr("height", height);
var center = [24.679341, 46.680381];
// Instantiate the projection object
var projection = d3.geo.conicConformal()
.center(center)
.clipAngle(180)
// Size of the map itself, you may want to play around with this in
// relation to your canvas size
.scale(10000)
// Center the map in the middle of the canvas
.translate([width/2, height/2])
.precision(.1);
// Assign the projection to a path
var path = d3.geo.path().projection(projection);
d3.json("https://code.highcharts.com/mapdata/countries/sa/sa-all.geo.json", function(err, data) {
$.each(data.features, function(i, feature) {
svg.append("path")
.datum(feature.geometry)
.attr("class", "border")
.attr("stroke", "black")
.attr("fill", "blue");
});
});
你的路徑沒有'd'屬性,所以它們實際上並沒有繪製任何東西,你需要使用d3-geo來轉換json的座標數據到svg路徑 –