Is it possible to trigger a mouseover event on the y-axis label in a chart? For instance, let's say we have a scatter plot with labels "area1", "area2", and "area3" on the y-axis. When a user hovers over the label "area1", a tooltip should appear displaying the description of area1. I haven't come across any examples of this. Does anyone know how to achieve this? Thank you!
I've also created a plunker that can be accessed here
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Plot</title>
<style>
.axis path,
.axis line{
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
</style>
</head>
<h1 style = "text-align:center;">Example</h1>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<div id="chart">
</div>
<script>
var data = [
{x: 5, y: "area1"
},
{x: 34, y: "area2"
},
{x: 19, y: "area3"
}
];
data.forEach(function(d){
d.x = +d.x;
d.y = d.y;
return console.log(data);
})
var m = {t:30, r:20, b:40, l:45 },
w = 600 - m.l - m.r,
h = 500 - m.t - m.b;
var x = d3.scale.linear()
.range([0, w])
.domain([0,d3.max(data, function(d){return d.x})]);
var y = d3.scale.ordinal()
.rangeRoundPoints([h-18,0])
.domain(data.map(function(d){return d.y;}));
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(8);
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(3);
var svg = d3.select("#chart")
.append("svg")
.attr("width", w + m.l + m.r)
.attr("height", h + m.t + m.b)
.style("margin-left", "auto")
.style("margin-right", "auto")
.style("display", "block")
.append("g")
.attr("transform", "translate(" + m.l + "," + m.t + ")");
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("class", "circles")
.attr({
cx: function(d) { return x(d.x); },
cy: function(d) { return y(d.y); },
r: 8
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + h + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
</script>
</body>
</html>