/* Volume series bars */ const volData = data.filter(d => d['volume']!== null && d['volume']!== 0); const yMinVolume = d3.min(volData, d => { return Math.min(d['volume']); }); const yMaxVolume = d3.max(volData, d => { return Math.max(d['volume']); }); const yVolumeScale = d3.scaleLinear().domain([yMinVolume, yMaxVolume]).range([height, 0]); The x and y axes for the volume series bar chart consist of the trade date and volume respectively.
svg.selectAll().data(volData).enter().append('rect').attr('x', d => { return xScale(d['date']); }).attr('y', d => { return yVolumeScale(d['volume']); }).attr('fill', (d, i) => { if (i === 0) { return '#03a678'; } else { return volData[i - 1].close > d.close?