这是我的d3强制布局:(请运行代码段)
var width = 600,
height = 600;
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
var color = d3.scale.category20();
var dataNodes = [
{ x: width/3, y: height/3 , group: 0, color: 'blue'},
{ x: 2*width/3, y: height/3, group: 1, color: 'red' },
{ x: width/2, y: 2*height/3, group: 2, color: 'green'}
];
var dataLinks = [
{ source: 0, target: 1},
{ source: 1, target: 2},
{ source: 2, target: 0}
];
var force = d3.layout.force()
.charge(-400)
.linkDistance(height/2) …Run Code Online (Sandbox Code Playgroud)