score:0
The changes you will want to make are here:
var xExtent = d3.extent(data, function(d) { return d.year; });
var yExtent = d3.extent(data, function(d) { return d.value; });
var x = d3.time.scale().domain(xExtent);
var y = d3.scale.linear().domain(yExtent);
Instead change your xExtent = [d3.min(data, d=>d.year), d3.max(data, d=>d.year) + someFactor]
where some factor can be something that will add two years.
My suggestion is to add 2 * 3.154e+10
as 3.154e+10
is one year in milliseconds, which is probably what is used under the hood.
Another way to do this (kinda hard-coded) is to do xExtent = [d3.min(data, d=>d.year), 2018]
, and make 2018 the max. This is of course less sustainable because the chart will not always show 2 extra years as your data becomes more current.
Source: stackoverflow.com
Related Query
- where to modify x axis length. AKA I want to show future years in chart
- Format Y axis values, original figures in millions, only want to show first three digits
- nvd3.js-Line Chart with View Finder: rotate axis labels and show line values when mouse over
- 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
- dimple.js Show X Axis label, but if "value" is null don't place a circle on chart
- D3.js v7 - How to make Y axis labels always show on screen for a scrollable chart
- D3 bar chart where axis labels are hyperlinks from data
- Show values on Y Axis as it is with Higher and lower limits NVD3 Line Chart
- Show value along with where needle is pointing in d3 gauge chart
- D3.js line chart, x axis have arbitrary dates, but want to show them sequental
- how to show axis in chart using jquery?
- NVD3 chart fails to calculate legend text length in Chrome, since Window.getComputedStyle does not return font-size correctly
- 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?
- D3 line chart axis text labels in multi line
- d3 show number instead of percentages on pie chart
- Make simple bar chart using C3 with separate columns on the x axis
- NVD3 Line Chart X Axis Ticks Are Missing
- what scale to use for representing years only on x axis in d3 js
- Stacked Area Chart in nvd3js - X Axis overflow
- d3.js - show large numbers on axis in abbreviated form
- Hide all text on y axis dc.js bar chart
- Setting Y axis range in dc series chart
- d3 bar chart y axis ticks and grid lines above max value
- add y axis label to NVD3 Multi-Bar Chart
- How to style slider on chart in D3.js and show label of dynamic y-value?
- c3.js - how to show hand cursor on bar chart hover
- Bar chart show values on top
- Don't show negative sign d3 axis labels
- Y axis label not displaying large numbers - Multi-Bar Chart
- DC.js bar chart with date axis
More Query from same tag
- How can I offset the source and target points of a bezier curve using D3's link generator?
- D3 graph is missing as much text elements as there are ticks in axis
- Need a vertical scroll in nvd3 multiBarHorizontalChart if no. of bars increases
- Zoom only when Ctrl + scrolling
- D3.js Select new JSON, lose image order and mouseover
- How can I map html data to d3?
- JS error for d3-brush in d3 v4 implementation
- d3.js: can't get padding working on rangeRoundBands?
- Responsive Donut Chart d3
- What are the values I need to create a hue-histogram?
- d3 steady horizontal transition along an SVG path
- Nodes not appearing for second line in d3.js
- How to use d3fc-label-label.js on a map?
- Array/Object JSON data.map is not a function D3.js v3
- filtering lines from a d3.layout.tree() if they link to nodes deeper than a certain value
- Grouped bar chart with zoom and updateable data error
- Are D3 value keys matched in the same way that default index numbers are when using enter()?
- Deleting node from graph is wrong
- D3 and React-Native
- Change width of ellipse when zooming
- D3.js: Joining json and csv not working
- How do I flip the text in my D3 collapsible radial tree?
- d3/chrome click/zoom bug?
- d3.js. How to update nested nodes?
- In D3.js, how to only add a comma on numbers with 5+ digits?
- D3.js: how to restrict dragging of x-axis in a grouped bar chart
- D3 TypeError when using URL to reference mbostock.github.com/d3/d3.js
- NVD3 - line chart NaN on safari using latest versions
- Incomplete graph in d3.js using json
- Hierarchical Edge Cluster Group Name