我與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