From cc0c17e53ae9ccd3aedc0f04b8f2208074bd5a7f Mon Sep 17 00:00:00 2001 From: yikth Date: Mon, 31 Aug 2020 12:01:39 +0800 Subject: [PATCH] add label to points --- playground/scatterplot.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/playground/scatterplot.js b/playground/scatterplot.js index 063693f..c0e8e97 100644 --- a/playground/scatterplot.js +++ b/playground/scatterplot.js @@ -17,6 +17,18 @@ svg.selectAll("circle") .data(dataset) .enter() .append("circle") -.attr("cx", d => d[0]) -.attr("cy", d => d[1]) -.attr("r", 5); \ No newline at end of file +.attr("cx", pt => pt[0]) +.attr("cy", pt => pt[1]) +.attr("r", 5); + +// create label for each point +svg.selectAll("text") + .data(dataset) + .enter() + .append("text") + .text(pt => `${pt[0]},${pt[1]}`) + .attr("x", pt => pt[0]) + .attr("y", pt => pt[1]) + .attr("font-family", "sans-serif") + .attr("font-size", "11px") + .attr("fill", "red"); \ No newline at end of file