|
|
|
@ -6,6 +6,14 @@ var dataset = [
|
|
|
|
const WIDTH = 600
|
|
|
|
const WIDTH = 600
|
|
|
|
const HEIGHT = 600
|
|
|
|
const HEIGHT = 600
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var xScale = d3.scaleLinear()
|
|
|
|
|
|
|
|
.domain([0, d3.max(dataset, d => d[0])])
|
|
|
|
|
|
|
|
.range([0, WIDTH]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var yScale = d3.scaleLinear()
|
|
|
|
|
|
|
|
.domain([0, d3.max(dataset, d => d[1])])
|
|
|
|
|
|
|
|
.range([0, HEIGHT]);
|
|
|
|
|
|
|
|
|
|
|
|
// Create SVG element
|
|
|
|
// Create SVG element
|
|
|
|
var svg = d3.select("body")
|
|
|
|
var svg = d3.select("body")
|
|
|
|
.append("svg")
|
|
|
|
.append("svg")
|
|
|
|
@ -17,8 +25,8 @@ svg.selectAll("circle")
|
|
|
|
.data(dataset)
|
|
|
|
.data(dataset)
|
|
|
|
.enter()
|
|
|
|
.enter()
|
|
|
|
.append("circle")
|
|
|
|
.append("circle")
|
|
|
|
.attr("cx", pt => pt[0])
|
|
|
|
.attr("cx", pt => xScale(pt[0]))
|
|
|
|
.attr("cy", pt => pt[1])
|
|
|
|
.attr("cy", pt => yScale(pt[1]))
|
|
|
|
.attr("r", 5);
|
|
|
|
.attr("r", 5);
|
|
|
|
|
|
|
|
|
|
|
|
// create label for each point
|
|
|
|
// create label for each point
|
|
|
|
@ -27,8 +35,8 @@ svg.selectAll("text")
|
|
|
|
.enter()
|
|
|
|
.enter()
|
|
|
|
.append("text")
|
|
|
|
.append("text")
|
|
|
|
.text(pt => `${pt[0]},${pt[1]}`)
|
|
|
|
.text(pt => `${pt[0]},${pt[1]}`)
|
|
|
|
.attr("x", pt => pt[0])
|
|
|
|
.attr("x", pt => xScale(pt[0]))
|
|
|
|
.attr("y", pt => pt[1])
|
|
|
|
.attr("y", pt => yScale(pt[1]))
|
|
|
|
.attr("font-family", "sans-serif")
|
|
|
|
.attr("font-family", "sans-serif")
|
|
|
|
.attr("font-size", "11px")
|
|
|
|
.attr("font-size", "11px")
|
|
|
|
.attr("fill", "red");
|
|
|
|
.attr("fill", "red");
|