我与D3世界地图实验和用这个例子来建立在:http://techslides.com/demos/d3/worldmap-template.htmlD3地图提示
现在我想实现一个类似于在地方的国家(即加亮和显示工具提示名称)绘制到地图上的城市。
到目前为止,我已粘贴并略微更改了国家/地区工具提示的代码,并试图将其与csv的城市日期连接起来。 这与原来的注释代码和我的复制粘贴的后半部分:
//function to add points and text to the map (used in plotting capitals)
function addpoint(lat,lon,text) {
var gpoint = g.append("g").attr("class", "gpoint");
var x = projection([lat,lon])[0];
var y = projection([lat,lon])[1];
gpoint.append("svg:circle")
.attr("cx", x)
.attr("cy", y)
.attr("class","point")
.attr("r", 1.5);
//conditional in case a point has no associated text
if(text.length>0){
gpoint.append("text")
.attr("x", x+2)
.attr("y", y+2)
.attr("class","text")
.text(text);
}
gpoint
.on("mousemove", function(d,i) {
var mouses = d3.mouse(svg.node())
.map(function(d) { return parseInt(d); });
tooltip.classed("hidden", false)
.attr("style", "left:"+(mouses[0])+"px;top:"+(mouses[1])+"px")
.html(d.CapitalName);
})
.on("mouseout", function(d,i) {
tooltip.classed("hidden", true);
});
现在当我将鼠标悬停在首都之一它给了我'不能读取属性未定义“CapitalName”。
任何人都可以帮助我吗?
你能不能给我们一个plunker或小提琴来看待? –
很想,但我是noob,不能让外部文件正确加载... – luoar
好吧,大家都是小菜鸟。试着设置它,我相信你可以做到这一点。或者上传到你自己的网站空间? – kwoxer