I would like to display HTML on the x-axis of my D3 graph. Basically, I want each label on the axis to be a hyperlink to another column from the data.
I tried
x.domain(data.map(function(d) { return "<a href=\"" + d.SiteUrl + "\">" + d.Name + "</a>"; }));
but it does not work at all. Instead of getting a hyperlink, I get the actual text value:
<a href="http://example.com">Something</a>
I also tried adding
.tickFormat(function(d) { return "<a href=\"" + d.SiteUrl + "\">" + d.Name + "</a>"; })
on the x axis, and also changing the value of .attr("x", ...) to
.attr("x", function(d) { return "<a href=\"" + d.SiteUrl + "\">" + x(d.Name) + "</a>"; })
on the chart itself.
Did I miss something?
source share