2014-11-24 82 views

回答

1

下面是一個示例,將div工具提示添加到您的圖表。

// create div add to DOM 
var div = d3.select("body").append("div") 
    .style("position", "absolute") 
    .style("width", "60px") 
    .style("height", "18px") 
    .style("background", "lightsteelblue") 
    .style("border-radius","4px") 
    .style("opacity", 0); 

..... 

// after you append the "arcs" 
// set up some mouse handler to show/hide div 
arcs.append("svg:path") 
      .attr("fill", function(d, i) { return color(i); }) 
      .attr("d", arc) 

    .on("mousemove", function(d) { 
     div.transition()   
      .duration(200)  
      .style("opacity", 0.9);  
     div.html("Seats: " + d.value) 
      .style("left", (d3.event.pageX) + "px")  
      .style("top", (d3.event.pageY - 28) + "px");  
     })     
    .on("mouseout", function(d) {  
     div.transition()   
      .duration(500)  
      .style("opacity", 0); 
    }); 

查看示例here

+0

非常感謝你馬克。它工作正常。 – Priya 2014-11-26 09:43:29