1. 程式人生 > >D3.js 繪制散點圖

D3.js 繪制散點圖

all pan 使用 坐標 ase span var enter 同時

對於散點圖,使用的數組需要包含坐標元素,即 x, y。同時,散點圖需要使用 circle 元素。

var svg = d2.select("body")
    .append("svg")
    .attr({
        width:w,
        height:h
})

svg.selectAll("circle")
    .data(dataset)
    .enter()
    .append("circle")
    .attr("cx",function(d){
        return d[0];
    })
    .attr("cy",function
(d){ return d[1]; }) .attr("r",5);

D3.js 繪制散點圖