Reputation: 473
I want to write a function, that returns a tick label with two lines of text. As I can see, an svg text tag is used for text labels. Is there a way to add tspan there or something?
Upvotes: 4
Views: 3929
Reputation: 34288
You can access the elements created by the axis
: Demo
d3.select('svg')
.append('g')
.attr('transform', 'translate(180, 10)')
.call(xAxis)
.selectAll('text') // `text` has already been created
.selectAll('tspan')
.data(function (d) { return bytesToString(d); }) // Returns two vals
.enter()
.append('tspan')
.attr('x', 0)
.attr('dx', '-1em')
.attr('dy', function (d, i) { return (2 * i - 1) + 'em'; })
.text(String);
Also, you'll have to set .tickFormat
to ''
on the axis
.
Upvotes: 5