chart = {
const svg = d3.create("svg")
.attr('viewBox', [0, 0, svgWidth, svgHeight])
.attr('height', svgHeight)
.attr('width', svgWidth);
const graph = svg
.append('g')
.attr('height', graphHeight)
.attr('width', graphWidth)
.attr(
'transform',
`translate(${(svgWidth - graphWidth) / 2}, ${
(svgHeight - graphHeight) / 2
})`,
);
graph
.selectAll('rect')
.data(data)
.join('rect')
.attr('width', x.bandwidth)
.attr('height', (d) => graphHeight - y(d.price))
.attr('x', (d) => x(d.name))
.attr('y', (d) => y(d.price))
.attr('fill', 'green')
.on('mouseover', function (e, d, i) {
tooltip
.html(
`<div>${d.name}</div>`)
.style('visibility', 'visible');
d3.select(this).attr('fill', 'blue');
})
.on('mousemove', function (e) {
tooltip
.style('top', e.pageY + 10 + 'px')
.style('left', e.pageX + 10 + 'px');
})
.on('mouseout', function () {
tooltip.html(``).style('visibility', 'hidden');
d3.select(this).transition().attr('fill', 'green');
});
svg
.append('g')
.attr(
'transform',
`translate(${graphMarginLeft}, ${graphMarginTop})`,
)
.call(yAxis);
svg
.append('g')
.attr(
'transform',
`translate(${graphMarginLeft}, ${
svgHeight - graphMarginTop
})`,
)
.call(xAxis);
return svg.node();
}