score:2
Accepted answer
Add the following function:
const getRange = d => {
const index = ageDomain.findIndex(item => item === d);
if(index === 0)
return `0 -- ${d}`;
else
return `${ageDomain[index-1] + 1} -- ${d}`;
}
Then, when creating the bottom axis, add the following line
.text(d => getRange(d))
after
.selectAll("text") :
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(xScale))
.selectAll("text")
.text(d => getRange(d))
.attr("transform", "translate(-10,0)rotate(-45")
.style("text-anchor", "end");
Source: stackoverflow.com
Related Query
- How can I customize the label of X axis, that means the label in X axis is different from the data
- How can I fix my chart so that the scale of the x axis is defined by a group of labels?
- How can I connect a circle to a path with a line that is perpendicular to the x axis to create an "error line"?
- How can I get the D3.js axis ticks and positions as an array?
- dimple.js How can I change the labels of a chart axis without changing the data?
- How to set the label for each vertical axis in a parallel coordinates visualization?
- How to get a value from a stylesheet into the code so that it can be used programmatically?
- how can I see the current element that represents a bar to which the hovering is applied
- How can I wrap the long label text in the bubble chart in d3?
- How to make axis "smart" and "flexible" so that the starting/end points on axis are sensible in D3 V4?
- How can I center my maps on the container and adjust the size so that it occupies the entire container?
- How can I scale an SVG so that the content drawn in it to fit the container size?
- How to change the data that appear on the axis using D3.js
- How can I create a basic bar chart with unique counts on the y axis and a category on the x axis?
- How can I retrieve the data-index of a class that contains a certain text?
- How can i show the labels on the x axis when there is data overlap in d3js?
- How to change the label of x axis in D3
- How can I make a bar chart starting from the 0 point of the y axis and not from the bottom of the svg?
- How can i set the x axis tick interval to be 1 in C3 / d3 js charts?
- How to convert the large bio-format file to database-like file that can be asynchronously accessed width JavaScript
- How can I continuously update the range of the x axis in d3 graph?
- Can I give the text and line elements that make up a D3 axis unique classes?
- How to make axis label of stacked bar chart in the middle of ticks chart in D3?
- How can I add a label with value to every point of the chart?
- How can I convert the unix date values along the axis of a d3.js graph to format dd-mm-yy?
- How to access the DOM element that correlates to a D3 SVG object?
- How can I bring a circle to the front with d3?
- d3.js - How can I set the cursor to hand when mouseover these elements on SVG container?
- How to customize the color scale in a D3 line chart?
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
More Query from same tag
- duplicating the whole svg element using d3.js
- d3 append an array of text
- Group by with multiple fields using d3.js
- d3 use drop down to filter for column headers
- Cross Hairs component throws error, dataset specific?
- Angular-UI tooltips on d3.js svg elements
- D3: can create a subset of elements, but not update them
- Angular 2.0 & D3.js don't apply Css on svg
- Ordering large time series datasets in BigQuery for export
- How to get a Rails variable into JavaScript file (D3)
- d3 grouped bar chart creation issue
- TypeError: Cannot read property 'childNodes' of undefined angular
- D3 chart curve has wrong data in tick label
- d3.js / without using the call method, you can view the x-axis?
- D3 Dendrogram - Not shown
- Modify link and node colours in Sankey with NetworkD3
- How to change speed of translate and scale when zooming in and out in D3 (using zoom.on & d3.event.translate, d3.event.zoom)?
- why xaxis and yaxis ticks don't appear on axes in D3?
- How to reuse the same pattern on multiple svg circles in d3.js
- Referencing different sets of elements using d3 js
- d3 multi-line chart with different names for features/variables
- change initial zoom in D3.js node graph
- Using index of parent on child in D3
- D3 scatter plot points not displaying correctly
- D3.JS Tree graph - Order of clicking is messing up the data
- control chart in d3?
- Transition speeds up after pause/resume
- lineChart not updating even if using the same dimension
- Making a grouped bar chart using d3.js
- D3 how to update text?