나는 똑같지 만 잘 맞출 수있는 몇 가지 방정식을 작성하려고했습니다. 각 막대의 맨 위에 툴팁을 표시해야합니다. Here is fiddle of the same어떻게하면 각 세로 막대의 위쪽에 툴팁을 표시 할 수 있습니까?
나는 당신은 마우스 오버 이벤트 핸들러 내부 d3.event를 사용해야 툴팁
sets.append("rect")
.attr("class","global")
.attr("width", xScale.rangeBand()/2)
.attr('y', function(d) {
return yScale((d.global/total)*100);
})
.attr("height", function(d){
return h - yScale((d.global/total)*100);
})
.attr('fill', function (d, i) {
return color(d.global);
})
.on('mouseover', function(d, i) {
var xPos = xScale.rangeBand()*i;
//console.log(xScale(i)); 6 190 282
console.log(xScale.rangeBand()*i);
var yPos = yScale((d.global/total) * 100);
d3.select('#hor_tooltip')
.style('left', xPos + 'px')
.style('top', yPos + 'px')
.style('display', 'block')
.html(d.global);
})
.on('mouseout', function() {
d3.select('#hor_tooltip').style('display', 'none');
})
.append("text")
.text(function(d) {
return commaFormat((d.global/total)*100);
})
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
나는 똑같은 작업을 해왔다. https://jsfiddle.net/c74eoo2b/10/ 이것이 당신이 암시 한 것입니까? – separ1
예, 방금 막대 위에 꼭두각시를 원한다고 생각했습니다 (상단). – Marcelo
d3.event.pagex의 위치는 무엇입니까? 마우스 위치? – separ1