这个 Q 相当老了,但只是为了记录:
据我所见,VIS 网络中的元素是通过在渲染图形时传递给它的函数的设置来设置样式的。这可能是因为 vis.js 将图形呈现到 HTML 画布上,该画布基本上是浏览器的黑盒,它不能动态地对其应用任何样式。
因此,请访问文档http://visjs.org/docs/network/并阅读可能的内容。通常,您可以更改颜色{填充、边框、文本}、字体系列、字体大小、节点形状、边缘样式等。
此外,示例库非常有用:http: //visjs.org/network_examples.html
我的设置示例:
var options = {
// tree style
layout: {
// this would make the tree directed
// hierarchical: {
// direction: LR,
// sortMethod: directed
// },
// this makes the tree always the same
randomSeed:2
},
interaction: {
dragNodes :false,
navigationButtons: true, // these need some more CSS
keyboard: true
},
// read the docs for this
physics: {
barnesHut: {
avoidOverlap: 0.99,
gravitationalConstant: -3300,
springLength: 150,
},
minVelocity: 0.75,
timestep: 0.9,
stabilization: {
enabled:true,
iterations:1000,
updateInterval:25
}
},
// general nodes settings
nodes: {
shape: 'box',
font: {
size: 14,
color: '#3f3f3f',
strokeWidth: 3,
strokeColor: 'white',
face: 'akrobat'
},
borderWidth: 2,
color: {
background: '#d7d7f3',
border: '#3030a9',
}
},
// settings for groups of nodes
groups: {
first: {
shape: 'diamond',
size: 5
},
second: {
shape: 'dot',
size: '8',
font: {
strokeWidth: 0,
size: 18
},
color: {
background: '#f3d7d7',
border: '#a93030'
}
}
},
// general edges setting
edges: {
font: {
align: 'middle',
face: 'arial'
},
smooth: {
forceDirection: none
}
}
};