chart = {
let svg, xAxis, yAxis, title;
if (!this) {
svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);
xAxis = svg
.append("g")
.attr("class", "xaxis")
.attr("transform", `translate(0,${height - margin.bottom})`);
yAxis = svg
.append("g")
.attr("class", "yaxis")
.attr("transform", `translate(${margin.left},0)`);
title = svg
.append("text")
.attr("class", "chart_title")
.attr("transform", `translate(${width / 2},15)`)
.style("text-anchor", "middle");
}
else {
svg = d3.select(this);
xAxis = svg.select(".xaxis");
yAxis = svg.select(".yaxis");
title = svg.select(".chart_title");
}
xAxis.call(xAxisFn);
yAxis.call(yAxisFn);
title.text("Chart title");
return svg.node();
}