score:4
Accepted answer
The main issue is putting the rectangles behind the lines. Given a date you can calculate its position on the corresponding axis like this - say you want to put a bar starting on 04/19/2013 and ending on 04/21/2013.
//here x is already the x axis time scale you have defined in your code
var left = x(new Date("Apr 19 2013"));
var right = x(new Date("Apr 22 2013")); //one more day
var wid = right - left;
svg.append("rect")
.attr("x", left)
.attr("width", wid)
.attr("height", height)
Now you can also add a style class to fill or stroke or set opacity etc. Adding click events should be easy but since there is no z-index for SVG which only relies on DOM order you can see if you can insert the rectangles before you insert the chart lines.
Source: stackoverflow.com
Related Query
- D3: How do you highlight a range of dates on D3 a line chart?
- How to add a fixed range vertical line to a D3.js chart
- How do you get JSON data and create a line chart with d3.js?
- How do you add multiple lines to a D3JS line chart where the depedent variable data sources start at different positions along the range?
- How to put data on line chart when x axis and data has a time range
- How do I set a different range for line chart embedded in a bar chart using d3.js
- How do you add a subtitle to multiple XY line chart in c3js.org?
- With nvd3.js/d3.js, how can you have a scatter or line chart with discrete/non-numeric/non-time-series X-Axis values?
- How can I keep tick marks from repeating when I have a small number of dates on an nvd3 chart
- How to limit a d3 line-chart from showing the line outside of the range of the axis?
- dc.js line chart with range of colors
- how to style style line chart points in c3js
- How to avoid overlapping tooltips of multi-series line chart d3.js
- how do you draw linear line in scatter plot with d3.js
- How do I get my area filled beneath my d3 line chart to be a gradient?
- How to add a line on x-axis on a horizontal bar chart in d3
- How to plot animated line chart using d3 while the data table is required to be updated every 1 second?
- How do I always keep my d3 line chart rollover text always visible?
- How to change the viewfinder (focus chart) of a NVD3 line chart programmatically?
- D3: How to use exit().remove() for Multi-Series Line Chart
- d3js line chart -- how to extend last step to end of range?
- How to create Stacked Line Chart D3, Multiple Y Axis and common X Axis
- How to draw a dynamic line chart based on an infotable?
- How to remove weekends dates from x axis in dc js chart
- D3: how to show lone point in a line chart
- How to add background shading to D3 line chart
- How to line up x axis on stacked bar chart with a line overlay in d3.js
- How to add circles onto line chart path d3.js
- How to change color of line in line chart using dimple.js?
- How to highlight only one datapoint in c3.js line graph?
More Query from same tag
- d3.js with coffeescript - use the timer make strange behavior
- D3 brushes: accessing absolute values from axis
- d3 - How to return d.type in v5?
- Trying to load a .tsv file from the front end. The file stays on my server. How do I do this using Express?
- How to interpret short drag events as clicks
- Making a scrollable tooltip in d3 pie chart
- D3 parcoords axis scale not updating correctly
- Gradually increment the opacity
- SVG manipulate gradiant fill color
- How to filter data and populate D3.js stacked bar chart?
- How to retrieve element's coordinates relative to an svg viewbox?
- How to add row in datatable - DC.js
- d3: what is the self as in d3.select(self.frameElement).style("height", height + "px");
- polygon weird redrawing by adding & dragging dynamic points (flickering)
- D3.js - Line Graph: Area path goes over x and y axis on zoom
- Draw an arc between two points
- Weird behaviour of a logarithmic scales in d3.js
- Nested JSON structure to build side-by-side d3.js charts
- Extending c3js with d3js code
- viewbox SVG attribute causes graphs to become spaced very far apart
- what means a type like SomeType<T, U, V> in typescript?
- Hebrew (and Arabic) text in SVG and Chrome workaround?
- 'd3.nest()' cannot read property of undefined
- An Area Chart With Tooltip in D3
- Having trouble with handling meteor js client and server side interactions
- D3 - Appending Rectangle Stops Tooltip From Working
- Angular Material rendering c3 charts
- Multiple straight line between two node in d3.js
- d3js simple donut chart not drawing path
- d3 v3 - sync brush zoom and scroll zoom