chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(geojson)
.attr("fill", "lightgrey")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);
svg.append("g")
.attr("fill", "red")
.attr("fill-opacity", 0.3)
.attr("stroke", "red")
.selectAll("path")
.data(voterData)
.join("path")
.attr("transform", d => {
d.position = projection([d.lng,d.lat])
return `translate(${d.position})`}
)
.attr("d", d => spike(length(d.voters)))
.append("title")
.text(d => `${d.mjesto}
${d3.format(".2s")(d.voters)}`);
const legend = svg.append("g")
.attr("fill", "#777")
.attr("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.selectAll("g")
.data(length.ticks(8).slice(1).reverse())
.join("g")
.attr("transform", (d, i) => `translate(${width*0.8 - (i + 1) * 28},520)`);
legend.append("path")
.attr("fill", "red")
.attr("fill-opacity", 0.3)
.attr("stroke", "red")
.attr("d", d => spike(length(d)));
legend.append("text")
.attr("dy", "1.3em")
.text(length.tickFormat(4, "s"));
return svg.node();
}