chart = {
const baseColor = "#CA8DFD"
const hoverColor = "#B042FF"
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.average))
.attr('x', (d) => x(d.name))
.attr('y', (d) => y(d.average))
.attr('fill', baseColor)
.on('mouseover', function (e, d, i) {
tooltip
.html(
`<div>${d.label}</div>`)
.style('visibility', 'visible');
d3.select(this).attr('fill', hoverColor);
})
.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', baseColor);
});
svg
.append('g')
.attr(
'transform',
`translate(${graphMarginLeft}, ${graphMarginTop})`,
)
.call(yAxis);
svg
.append('g')
.attr(
'transform',
`translate(${graphMarginLeft}, ${
svgHeight - graphMarginTop
})`,
)
.call(xAxis);
svg.append("text")
.attr("x", (graphWidth / 2)+(svgWidth - graphWidth) / 2)
.attr("y", svgHeight - 5)
.attr("text-anchor", "middle")
.attr("font-size", "14px")
.text("State");
svg.append("text")
.attr("x", -(10 + svgHeight / 2))
.attr("y", 15)
.attr("transform", "rotate(-90)")
.attr("text-anchor", "middle")
.attr("font-size", "14px")
.text("Average Telemedecine Score");
return svg.node();
}