score:2
since you have a time scale, you cannot simply multiply the domain values by a given number, as the answer linked in the comments correctly does (which is the most common solution for a linear scale).
in a time scale, you can add or subtract time using interval.offset
.
for instance, in your case, i'll subtract 10 seconds from the first date and add 10 seconds in the last date:
var x = d3.scaletime()
.domain([d3.timesecond.offset(d3.min(data[0], function(d) {
return d.inspected_at;
}), -10),
d3.timesecond.offset(d3.max(data[0], function(d) {
return d.inspected_at;
}), +10)
])
.range([0, width - 100]);
that should be enough, but you can change that magic number the way you want.
also, it's worth mentioning that interval.offset
is way easier and handier than the js alternatives, since you can use d3.timesecond
for seconds, d3.timeminute
for minutes, d3.timeday
for days and so on, adding or subtracting the necessary amount of seconds, minutes, days, weeks etc you want.
here is the updated codepen: https://codepen.io/anon/pen/nbeyrn?editors=0010
Source: stackoverflow.com
Related Query
- Create a padding for the first and last data points using a time scale
- D3: Create a continuous color scale with many strings/inputs for the range and dynamically changing values of the domain
- Create synchronous loading of data using D3.js and drawing following the loading
- Time in x-axis and data for the y-axis for line chart in d3.js doesn't match/show with what (data) is on JSON
- How to show the unhighlighted/ not selected data points on scatter plots when using brush/group in dc.js? And is multiple brushes possible in dc.js
- SVG - Create a path to join midpoints of group of circles and further extend till circumference points of first & last circle
- How to plot points on a map projection in D3.js and filter the data using range sliders?
- D3js: How to load a tsv file and select only the data which is available for two different points
- How to hide the ticks for first child and last child in n3-charts
- Display Bar Chart for Last week, Last Month, and Last Year Data from JSON using D3.js
- Using an ordinal scale ('d3.scale.ordinal') for the x-axis in a bar chart
- how to create labels for data in donut chart using d3.js
- Data points and ticks in the scaleBand axis are not aligned
- d3 using a different X scale and Y scale domain for each selection
- How do I create a minimap of an SVG using D3 v5 and show the current viewport dimensions?
- Create data visualizations using Express and get data from a PostgreSQL database
- d3 time scale - last bar on graph is appearing outside of the graph
- How to get the boundaries of currently visible time scale (after panning and zooming)?
- How to increase time to read d3.json data for large data set and slow networks?
- Time axis: Remove scale points with no data
- How can I offset the source and target points of a bezier curve using D3's link generator?
- How can I apply a time scale and show my data in intervals of "n" years?
- Changing time scale from days to weeks, how do I update and sum data values?
- In a d3 scatterplot using data from a csv file, how do i draw lines connecting related points when the mouse is over a point?
- How would I create my own color scale based on the id of my data in d3?
- I can't see the div for the 1st object data using D3
- How can I control the date format for d3 scaleTime and remove unwanted clock time ticks?
- How do you find the last data point in d3 and draw a circle and a line on it?
- using a multi array for plotting data on a scatter with dc.js, d3 and crossfilter
- Wrong values returned for x(i) when using time scale in D3.js
More Query from same tag
- Add opacity to d3 colorScale
- D3.js keyboard controls (tab)
- How to exit().transition rects under a col in d3
- Forect layout graph is re-drawing in D3 when meteor db updates
- D3JS - Can I make a force-directed graph with individual nodes and how?
- Cut off gridline at the end in d3.js
- Real time charts with D3.js
- How to remove padding in c3.js?
- Hiding visible elements on click D3.js
- I dont understand why my d3js chart is not updating though it passes through update function
- mpld3 plugin to set xtics
- How to call a Rails model method in d3.js?
- D3js geo map with percentage based dynamic fill
- Error with interpolate
- How to rotate text around its centroid (vertically flip) in SVG / D3?
- Getting transition values in D3
- Why is label not getting added to all my paths?
- Two bar charts from same data object using D3.js
- d3js set X axis tick position
- Existing nodes freeze upon new data entering
- Is there a way to access enter and update selections together?
- D3 reusable chart tootip follows wrong chart when update
- d3 Click to create circle and click to remove
- Multiple Y axes in nvd3 scatter graph
- Get Y value with given X value
- Want to show unique values only using d3.js not working
- d3 custom order bar series with two categories
- Unnesting and reducing data structures in javascript
- how can i use correctly the functions which have been already developed in javascript into an application in angular 4?
- D3 bar char x-axis line not displaying