2013-04-12 45 views
0
var raphael = new Raphael(document.body,500,500); 
raphael.setStart(); 
var d3_raphael = d3.raphael(raphael); 
var stuff = {className:"", children:[ 
{className:"TVI", packageName:'aa', value:2000}, 
{className:"SIC", packageName:'aa', value:1520}, 
{className:"RTP1", packageName:'bb', value: 1400}, 
{className:"SIC", packageName:'aa', value:1220}, 
{className:"RTP1", packageName:'bb', value: 1100}, 
{className:"SIC", packageName:'aa', value:920}, 
{className:"RTP1", packageName:'bb', value: 800}, 
{className:"SIC", packageName:'aa', value:1520}, 
{className:"RTP1", packageName:'bb', value: 1400}, 
{className:"SIC", packageName:'aa', value:1220}, 
{className:"RTP1", packageName:'bb', value: 1100}, 
{className:"SIC", packageName:'aa', value:920}, 
{className:"RTP2 manoj", packageName:'bb', value: 550} 
]}; 

var r = 400, 
format = d3.format(",d"), 
fill = d3.scale.category10(); 

var bubble = d3.layout.pack() 
.sort(function(a, b) {return b.value - a.value;}) 
.size([r, r]); 

var chart = d3_raphael.select("body").append("svg:svg") 
.attr("width", r) 
.attr("height", r) 
.attr("class", "bubble");  
var node = chart.selectAll("circle") 
.data(bubble.nodes(stuff)) 
.enter().append("circle") 
    .attr("class", "node") 
    .attr("cx",function(d) { return d.x; }) 
    .attr("cy",function(d) { return d.y; }) 
    .attr("r", function(d) { return d.r; }) 
    .attr("fill", function(d) { return fill(d.packageName); }) 
    .mouseover(function() { 
    circle.append("<p>MouseOver</p>"); 
}); 

但它給我的錯誤, Uncaught TypeError: Object [object Array] has no method 'mouseover'。我想通過事件添加所有的鼠標就可以了我想用raphael爲我的代碼添加mouseover事件?

如何來解決這個問題。

+0

你確定這是拉斐爾?看起來更像我的d3.js。 – mihai

+0

實際上它是D3,但我使它與低版本的ie兼容。我正在編輯我的帖子再次查看。 – Manu

回答

0

在D3做到這一點的方法是使用on()功能:

.on("mouseover", function() { 
    d3.select(this).append("<p>MouseOver</p>"); 
}); 

注意<p>標籤將不會在SVG工作 - 但是你可以使用foreignObject。例如參見here

+0

謝謝拉爾斯......但我使用var raphael = new Raphael(document.body,500,500); raphael.setStart(); var d3_raphael = d3.raphael(raphael);所以它不工作,它給了我未捕獲的異常。 – Manu

+0

你收到了什麼錯誤信息? –

+0

Uncaught TypeError:Object [object Array]沒有方法'mouseover' – Manu