728x90
- 다르게 표현
//Circle Data Set
var circleData = [
{ "cx": 20, "cy": 20, "radius": 20, "color" : "green" },
{ "cx": 70, "cy": 70, "radius": 20, "color" : "purple" }];
//Create the SVG Viewport
var svgContainer = d3.select("body").append("svg")
.attr("width",200)
.attr("height",200);
//Add circles to the svgContainer : virutal element 만들기
var circles = svgContainer.selectAll("circle")
.data(circleData)
.enter()
.append("circle");
//Add the circle attributes : data binding to element
var circleAttributes = circles
.attr("cx", function (d) { return d.cx; })
.attr("cy", function (d) { return d.cy; })
.attr("r", function (d) { return d.radius; })
.style("fill", function (d) { return d.color; });
//Add the SVG Text Element to the svgContainer : virtual element 만들기
var text = svgContainer.selectAll("text")
.data(circleData)
.enter()
.append("text");
//Add SVG Text Element Attributes 텍스트 : data binding to element
var textLabels = text
.attr("x", function(d) { return d.cx; })
.attr("y", function(d) { return d.cy; })
.text( function (d) { return "( " + d.cx + ", " + d.cy +" )"; })
.attr("font-family", "sans-serif")
.attr("font-size", "20px")
.attr("fill", "red");
728x90
'JavaScript' 카테고리의 다른 글
[vue.js] Spring Boot & Vue.js 연동 (1) (0) | 2023.08.16 |
---|---|
[vue.js] visual studio code (VS code) 설치하기 및 Vue 프로젝트 생성 (0) | 2023.08.16 |
json data 설정 새로운방법/ key : value (0) | 2021.10.05 |
[Node.js] 시퀄라이즈 where/ OP. (0) | 2021.09.29 |
[Node.js] sequelize.import is not a function error 에러 해결 (0) | 2021.09.08 |