score:54
If you have absolute time, you probably want to convert your x data to JavaScript Date objects rather than simple numbers, and then you want to use d3.time.scale and d3.time.format. An example of "hh:mm" format for an axis would be:
d3.svg.axis()
.scale(x)
.orient("bottom")
.tickFormat(d3.time.format("%H:%M"));
And actually, you may not need to specify a tick format at all; depending on the domain of your scale and the number of ticks, the default time scale format might be sufficient for your needs. Alternatively, if you want complete control, you can also specify the tick intervals to the scale. For example, for ticks every fifteen minutes, you might say:
d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(d3.time.minutes, 15)
.tickFormat(d3.time.format("%H:%M"));
If you have relative time, i.e. durations, (and hence have numbers representing minutes rather than absolute dates), you can format these as dates by picking an arbitrary epoch and converting on-the-fly. That way you can leave the data itself as numbers. For example:
var formatTime = d3.time.format("%H:%M"),
formatMinutes = function(d) { return formatTime(new Date(2012, 0, 1, 0, d)); };
Since only the minutes and hours will be displayed, it doesn't matter what epoch you pick. Here’s an example using this technique to format a distribution of durations:
Source: stackoverflow.com
Related Query
- How do I make a custom axis formatter for hours & minutes in d3.js?
- D3.js v7 - How to make Y axis labels always show on screen for a scrollable chart
- How to make same axis range for numeric attributes and different axis range for ordinal group
- How to make hour and minutes as x axis in nvd3.js graph
- How to replace X axis numerical values(years) with custom labels in D3.js for this example?
- How do properly use an array label names for a custom axis on D3?
- How to make localization on months / days for D3js?
- How to display the value for the final tick on axis in D3?
- How to make curved lines to straight lines for Hierarchy Chart using d3.js
- How do I generate axis tick for every year in D3?
- How can I connect two parent node into one child node and how to make a tooltip for each node in the tree pragmatically? in D3 js (SVG)
- How to make a tiled image pyramid for leaflet from a non-geographic source
- How to make the NVD3 discreteBarChart labels on the X axis to adapt to the width or to the number of labels?
- custom x axis tooltip for nvd3 scatter chart
- How to modify axis labels in d3 for a stacked bar chart when the axis labels are mapped as part of the scale's domain
- How to set the label for each vertical axis in a parallel coordinates visualization?
- d3.js, how can i create an axis with custom labels and customs ticks?
- d3.js how to place custom labels on horizontal log scaled axis
- How to make axis tick labels hyperlinks in D3.js
- How to cut y axis to make the chart look better?
- How to make D3.js use UTC times for the x-axis, with Moment.js
- How to make the .data() call for this data format?
- how to make the x axis scrollable in a d3 line chart graph
- Axis with log scale, how to include tick for 0?
- How to specify 3 different custom colors for 3 nodes in D3 force layout on load
- Custom label for x axis on nvd3 graphs
- how to display data from 1st point on words on y axis for line chart in d3.js
- How to specify custom children and parent property for tree layout in D3
- How to spcify ticks on x axis for time scale in d3js?
- How to make axis "smart" and "flexible" so that the starting/end points on axis are sensible in D3 V4?
More Query from same tag
- why d3 line is drawn only when i put data within in line function?
- Parsing x-axis with D3 error for column chart
- I am getting a 'Callback is undefined error' in d3
- rounded corners to a rectangle?
- How to get d3 to recognize push+shift as an add-new-object-to-end and remove-old-object-from-beginning, rather than as just a data change in place
- How to make data() key function to work with TypeScript?
- Bostock's d3 Object Constancy example: what is effect of d3.transition().each?
- How to apply individual parameters to easing in transitions?
- d3 line chart not showing,can not read in date data
- Error: <rect> attribute y: Expected length, "NaN"
- how to get dynamic value of input element with d3?
- D3.js check to see if a node has a class
- How to apply isotope to svg nodes
- d3.js - filling `image` from pattern shrinks the image size
- D3.js force layout - edge label placement/rotation
- Automatic Layout of Swimlane Graphs
- d3.js line chart with negative numbers
- How to show c3.js data in table
- How to include two htmls into another html using jQuery
- Replacing JSON file with CSV for d3js
- Invalid regular expression in d3.v5
- Creating world choropleth map with D3
- Customize grid lines in D3 grouped bar chart
- Update the colored area of a line chart
- Is this JSON I made using jsonify with flask and python 3 formatted correctly for making a D3 graph? And if not, how should I format it?
- D3 Click Event Handler
- How to assign the center of d3.forceRadial dynamically using functions?
- Why is sankeyNetwork in R not showing different colors?
- d3 getting array of keys from data
- Zoomable, Google-Finance-style time series graph in D3 or Rickshaw?