D3을 사용하여 작성할 수있는 SVG의 수는 제한이 없습니다. 모든 D3은 DOM에 액세스하여 브라우저가 SVG를 그리거나 SVG를 조작하는 방법을 알고 있도록 수정합니다. D3을 사용하면 요소에 더 쉽게 액세스하고 함께 작업 할 수 있습니다.
JSON 개체에서 SVG를 읽는 경우 여러 JSONS를 읽는 것만으로도됩니다.
는 "morley.csv"를 열고 데이터와 함께 작동합니다, 박스 플롯의 예에서 ...
d3.csv("morley.csv", function(error, csv) {
var data = [];
csv.forEach(function(x) {
var e = Math.floor(x.Expt - 1),
r = Math.floor(x.Run - 1),
s = Math.floor(x.Speed),
d = data[e];
if (!d) d = data[e] = [s];
else d.push(s);
if (s > max) max = s;
if (s < min) min = s;
});
chart.domain([min, max]);
var svg = d3.select("body").selectAll("svg")
.data(data)
.enter().append("svg")
.attr("class", "box")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.bottom + margin.top)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.call(chart);
d3.select("button").on("click", function() {
svg.datum(randomize).call(chart.duration(1000)); // TODO automatic transitions
});
});
이, 예로서 D3js.org 웹 사이트에서 처음 두 예제를 가져 가라.
d3.json("flare.json", function(error, root) {
var node = svg.selectAll(".node")
.data(bubble.nodes(classes(root))
.filter(function(d) { return !d.children; }))
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("title")
.text(function(d) { return d.className + ": " + format(d.value); });
node.append("circle")
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return color(d.packageName); });
node.append("text")
.attr("dy", ".3em")
.style("text-anchor", "middle")
.text(function(d) { return d.className.substring(0, d.r/3); });
});
이것은 거품 형 차트 예제에서 "flare.json"을 열고 그걸로 작업을 시작합니다. 같은 파일에서 두 가지 작업을 모두 수행하는 것을 막을 수있는 방법은 없습니다.
당신이 알아야 할 것은 다른 프로그램과 마찬가지로 변수 참조입니다. 각 SVG는 자체 참조가 필요합니다. 위의 두 코드 블록은 여러 변수에 대해 동일한 변수 이름을 사용하므로 서로 밟을 수 있습니다. 두 페이지를 한 페이지에 넣으려면 변수의 이름을 고유하게 바꾸기 만하면됩니다. 누군가가 어쩌면 IE9 원인은 크롬과 파이어 폭스이 테스트 같은이를 개선하기 위해 포인터를 가지고있는 경우
정말 thourough 대답을위한 고맙습니다. 나는 그것을 파헤쳐 볼 것이다 !!! 그것은 나를 위해 조금 복잡하지만 어디 선가 시작하지 않았습니까?! – myradon