如何使用Vis.js库在我的网络中设置选项?
我找不到任何答案。 每个人都说:
network.setOptions(options);
但我不明白。我该如何编辑这些选项?
我想在网络中切换zoomView。
$("#zoom-network").click(function(e) {
// what to do here ?
network.setOptions(options);
});
修改 感谢AlexP,我找到了答案:
$("#zoom-network").click(function(e) {
var options = {
interaction : {
zoomView : true
}
};
network.setOptions(options);
});
答案 0 :(得分:1)
对于缩放等动画,您必须使用.moveTo
$("#zoom-network").click(function(e) {
var options = {
scale: 1.5,
animation: {
duration: 1000,
easingFunction: "easeInOutQuad"
}
}
network.moveTo(options);
});
答案 1 :(得分:0)
<!doctype html>
<html>
<head>
<title>Network | Basic usage</title>
<script type="text/javascript" src="../../dist/vis.js"></script>
<link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#mynetwork {
width: 600px;
height: 400px;
border: 1px solid lightgray;
}
</style>
</head>
<body>
<p>
Create a simple network with some nodes and edges.
</p>
<div id="mynetwork"></div>
<script type="text/javascript">
// create an array with nodes
var nodes = new vis.DataSet([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
// create an array with edges
var edges = new vis.DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5}
]);
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {};
var network = new vis.Network(container, data);
network.setOptions(options);
</script>
</body>
</html>
答案 2 :(得分:0)
您可以设置单个选项(例如,如果您有一个有效的日期,您可能只希望设置“结束”选项)。因此,假设您有一个先前设置的选项对象,如上面的答案中所示,没有设置“结束”选项,您将使用如下代码:
if (this.end != null) {
this.options["end"] = this.end;
}