大家好,又见面了,我是全栈君。
<!doctype html> <html> <head> <title>Random nodes</title> <style type="text/css"> body { font: 13pt "courier new"; } #mynetwork { width: 600px; height: 600px; border: 8px solid blueviolet; } </style> <script type="text/javascript" src="VisJS/dist/vis.js"></script> <script type="text/javascript"> function draw(){ var nodes = []; var edges = []; var countConnected = []; var nodeCount = document.getElementById( "nodeCount" ).value; for( var i = 0; i < nodeCount; ++i ){ nodes.push( { id: i, label: String( i ) } ); countConnected[i] = 0; if( i == 1 ){ edges.push( { from: i, to: 0 } ); countConnected[i]++; countConnected[0]++; } else if( i > 1 ){ var rand = Math.floor( Math.random() * edges.length * 2 ); var limit = countConnected.length; var val = 0; var j = 0; while( val < rand && j < limit ){ val += countConnected[j]; j++; } edges.push( { from: i, to: j } ); countConnected[i]++; countConnected[j]++; } } var container = document.getElementById( "mynetwork" ); var data = { nodes: nodes, edges: edges }; var options = { edges: {}, stabilize: false }; var net = new vis.Network( container, data, options ); } </script> </head> <body onload="draw();"> <form onsubmit="draw(); return false;"> <label for="nodeCount">Number of nodes:</label> <input id="nodeCount" type="text" value="10" style="width: 50px;"> <input type="submit" value="Go"> </form> <br> <div id="mynetwork"></div> </body> </html>
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/115529.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...