score:4
(Based on https://groups.google.com/d/msg/d3-js/zoUjrm75iCg/EJg0YhnTw3YJ)
The trick is to use svg:foreignObject
(as stated by @thatOneGuy in the comments), then you can place any HTML inside the axis label. The function at html
below gets passed data[i].name
, where one can place arbitrary HTML.
var height = 500;
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.tickSize(0).tickPadding(0).tickFormat(function(d) {return '';});
var tx = -5;
var ty = 2;
var tw = 50;
var th = 10;
chart.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.selectAll("g")
.append("svg:foreignObject")
.attr("width",tw)
.attr("height",th)
.attr("x", tx)
.attr("y", ty)
.append("xhtml:div")
.attr("class", "my-x-axis-label")
.html(function(schema) {return schema;});
CSS:
div.my-x-axis-label {
font: 10px sans-serif;
}
Source: stackoverflow.com
Related Query
- Render HTML on X-Axis Ticks
- How to render end ticks always using d3 svg axis
- d3.js: Align text labels between ticks on the axis
- How can I get the D3.js axis ticks and positions as an array?
- D3 - using strings for axis ticks
- Multiline svg text axis ticks in d3
- How to force a specific amount of y axis ticks in d3 charts?
- D3v4 time scale axis error in ticks display
- NVD3 Line Chart X Axis Ticks Are Missing
- d3.js make axis ticks clickable
- Ticks only at the start and end of an axis
- How to set fixed no. of ticks on axis in d3.js?
- Data points and ticks in the scaleBand axis are not aligned
- d3 bar chart y axis ticks and grid lines above max value
- D3 Axis ticks hard count
- Shorten months ticks on x axis
- D3 time scale axis ticks are irregular on year boundaries
- Display only values from the data set into X axis ticks
- NVD3 - configuring ticks on axis
- Need help lining up x axis ticks with bars in D3.js bar chart
- dc.js bar chart with ordinal x axis scale doesn't render correctly
- Manually positioning ticks on axis - D3
- Add text to outer ticks of a D3 axis
- Limit number of Y axis ticks by keeping a top tick above the bar in d3
- How to get axis ticks out of d3 without rendering in SVG?
- Bind data to axis ticks d3.js
- How to add on-click events to D3 axis ticks
- Custom quantized ticks on axis
- Is it possible to make axis ticks with appended text to have dynamic padding in d3?
- How to remove the comma in D3 axis ticks and remove the last tick?
More Query from same tag
- Rails 3 generating json file to use it in javascript library - D3.js
- crossfilter, d3.brush and nvd3 integration
- D3 - changing the data of multiple lines onclick
- Chart won't redraw in `onchange` function
- D3 not updating label
- D3 scale based on window size
- nvd3.js chart ajax data redraw - missing hovereffect + former yAxis scale
- d3 - draw grid lines at specified locations
- NVD3 line chart - legend text cut off
- Link Length and Strength from attribute
- D3.js tick format: show when month changes
- d3 change scale domain and keep the zoom working as expected
- D3: Merge interior svg paths?
- svg image not visible after reload
- Grouping text and rect
- Angular 6 and D3 v.5.5, this.<variable> undefined
- d3 bar chart with range selector in x-axis (like dygraphs)
- Tree with no child and no parent using d3
- My D3.js code cause new data to be added as a new graph, I want it to be appended to an existing graph. What did I do wrong?
- Pan during dragging in D3JS
- How to fix Y-Axis range in d3.js graphs
- Sankey Diagram in d3
- D3.js How to create just 1 element that is binded to a dataset of multiple data items
- Line chart/graph with an irregular threshold field
- Draw multiple circles using d3.js in a 3x3 format
- How to show the Bar on the horizontal ticks - in D3.js
- Textpath in circle packing not zooming correctly
- Width limit on D3 force layout centers
- D3- how to select circles in a group element and set display to none
- d3 localStorage compare arrays .filter coffee script; array variable not working