{
const svg = d3.create('svg')
.attr('width', totalWidth)
.attr('height', totalHeight);
const g = svg.append("g")
.attr('transform', `translate(${margin.left}, ${margin.top})`);
g.selectAll('.rect1')
.data(aggregated)
.join('rect')
.attr('x',0)
.attr('y', d => y(d.classType))
.attr('width', d => x(d.Number))
.attr('height', y.bandwidth())
.attr('fill', totalColor);
const yText = {
"1": "First",
"2": "Second",
"3": "Third",
};
const yAxis = d3.axisLeft(y).tickFormat(d => yText[d]);
const xAxis = d3.axisBottom(x)
g.append('g')
.call(yAxis)
.call(g => g.select('.domain').remove())
.append('text')
.attr('fill', 'black')
.attr('font-family', 'sans-serif')
.attr('x', 0)
.attr('y', 0)
.text("Class Type")
.attr('font-size', '14px');
g.append('g')
.attr('transform', `translate(0, ${visHeight})`)
.call(xAxis)
.call(g => g.select('.domain').remove())
.append('text')
.attr('fill', 'black')
.attr('font-family', 'sans-serif')
.attr('x', visWidth / 2)
.attr('y', 40)
.text("Number of passengers")
.attr('font-size', '14px');
g.selectAll('.rect2')
.data(q1Data)
.join('rect')
.attr('x',0)
.attr('y', d => y(d.classType))
.attr('width', d => x(d.value))
.attr('height', y.bandwidth())
.attr('fill', 'orange');
g.selectAll('.text')
.data(results)
.join('text')
.attr('x',d => x(d.value))
.attr('y', d => y(d.classType))
.text(d=>d.percentage+" % ");
return svg.node();
}