chart = {
const svg = d3.select(DOM.svg(width, height));
const bar = svg.append('g');
bar.append('g')
.call(xAxisBar);
bar.append('g')
.call(yAxisBar);
bar.selectAll('rect')
.data(data)
.join('rect')
.attr('x', d => xBar(0))
.attr('y', (d, i) => yBar(i))
.attr('width', d => xBar(d.peakDeaths) - xBar(0))
.attr('height', yBar.bandwidth())
.attr('fill', 'purple')
.on('mouseover', function(d) {
d3.select(this).attr('fill', 'steelblue');})
.on('mouseout', function(d) {
d3.select(this).attr('fill', 'purple');})
.on('click', function(e, d, i){
drawLineChart(d);
});
const lineChart = svg.append('g')
.attr('transform', `translate(0,${heightBar+padding})`);
lineChart.append('g')
.call(xAxisLine);
lineChart.append('g')
.call(yAxisLine);
lineChart.append('text')
.attr('id', 'title')
.attr('x', width - margin.right)
.attr('y', margin.top +15)
.attr('text-anchor', 'end')
.attr('font-size', '15px')
.attr('font-weight', 'bold')
.attr('font-family', 'sans-serif');
function drawLineChart(d) {
lineChart.selectAll('path').remove();
lineChart.select('#title')
.text(d.location);
lineChart.append('path')
.datum(d['data'])
.transition()
.attr('stroke', 'purple')
.attr('stroke-width', 1.5)
.attr('fill', 'none')
.attr('d', line(key));
}
return svg.node();
}