force2.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="ECharts">
  8. <meta name="author" content="kener.linfeng@gmail.com">
  9. <title>ECharts · Example</title>
  10. <link rel="shortcut icon" href="../asset/ico/favicon.png">
  11. <link href="../asset/css/font-awesome.min.css" rel="stylesheet">
  12. <link href="../asset/css/bootstrap.css" rel="stylesheet">
  13. <link href="../asset/css/carousel.css" rel="stylesheet">
  14. <link href="../asset/css/echartsHome.css" rel="stylesheet">
  15. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <script src="./www/js/echarts.js"></script>
  21. <script src="../asset/js/codemirror.js"></script>
  22. <script src="../asset/js/javascript.js"></script>
  23. <link href="../asset/css/codemirror.css" rel="stylesheet">
  24. <link href="../asset/css/monokai.css" rel="stylesheet">
  25. </head>
  26. <body>
  27. <!-- Fixed navbar -->
  28. <div class="navbar navbar-default navbar-fixed-top" role="navigation" id="head"></div>
  29. <div class="container-fluid">
  30. <div class="row-fluid example">
  31. <div id="sidebar-code" class="col-md-4">
  32. <div class="well sidebar-nav">
  33. <div class="nav-header"><a href="#" onclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div>
  34. <textarea id="code" name="code">
  35. var nodes = [];
  36. var links = [];
  37. var constMaxDepth = 2;
  38. var constMaxChildren = 7;
  39. var constMinChildren = 4;
  40. var constMaxRadius = 10;
  41. var constMinRadius = 2;
  42. function rangeRandom(min, max) {
  43. return Math.random() * (max - min) + min;
  44. }
  45. function createRandomNode(depth) {
  46. var node = {
  47. name : 'NODE_' + nodes.length,
  48. value : rangeRandom(constMinRadius, constMaxRadius),
  49. // Custom properties
  50. id : nodes.length,
  51. depth : depth,
  52. category : depth === constMaxDepth ? 0 : 1
  53. }
  54. nodes.push(node);
  55. return node;
  56. }
  57. function forceMockThreeData() {
  58. var depth = 0;
  59. var rootNode = {
  60. name : 'ROOT',
  61. value : rangeRandom(constMinRadius, constMaxRadius),
  62. // Custom properties
  63. id : 0,
  64. depth : 0,
  65. category : 2
  66. }
  67. nodes.push(rootNode);
  68. function mock(parentNode, depth) {
  69. var nChildren = Math.round(rangeRandom(constMinChildren, constMaxChildren));
  70. for (var i = 0; i < nChildren; i++) {
  71. var childNode = createRandomNode(depth);
  72. links.push({
  73. source : parentNode.id,
  74. target : childNode.id,
  75. weight : 1
  76. });
  77. if (depth < constMaxDepth) {
  78. mock(childNode, depth + 1);
  79. }
  80. }
  81. }
  82. mock(rootNode, 0);
  83. }
  84. forceMockThreeData();
  85. option = {
  86. title : {
  87. text: 'Force',
  88. subtext: 'Force-directed tree',
  89. x:'right',
  90. y:'bottom'
  91. },
  92. tooltip : {
  93. trigger: 'item',
  94. formatter: '{a} : {b}'
  95. },
  96. toolbox: {
  97. show : true,
  98. feature : {
  99. restore : {show: true},
  100. magicType: {show: true, type: ['force', 'chord']},
  101. saveAsImage : {show: true}
  102. }
  103. },
  104. legend: {
  105. x: 'left',
  106. data:['叶子节点','非叶子节点', '根节点']
  107. },
  108. series : [
  109. {
  110. type:'force',
  111. name : "Force tree",
  112. ribbonType: false,
  113. categories : [
  114. {
  115. name: '叶子节点'
  116. },
  117. {
  118. name: '非叶子节点'
  119. },
  120. {
  121. name: '根节点'
  122. }
  123. ],
  124. itemStyle: {
  125. normal: {
  126. label: {
  127. show: false
  128. },
  129. nodeStyle : {
  130. brushType : 'both',
  131. borderColor : 'rgba(255,215,0,0.6)',
  132. borderWidth : 1
  133. }
  134. }
  135. },
  136. minRadius : constMinRadius,
  137. maxRadius : constMaxRadius,
  138. coolDown: 0.995,
  139. steps: 10,
  140. nodes : nodes,
  141. links : links,
  142. steps: 1
  143. }
  144. ]
  145. };
  146. </textarea>
  147. </div><!--/.well -->
  148. </div><!--/span-->
  149. <div id="graphic" class="col-md-8">
  150. <div id="main" class="main"></div>
  151. <div>
  152. <button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
  153. <span class="text-primary">切换主题</span>
  154. <select id="theme-select"></select>
  155. <span id='wrong-message' style="color:red"></span>
  156. </div>
  157. </div><!--/span-->
  158. </div><!--/row-->
  159. </div><!--/.fluid-container-->
  160. <footer id="footer"></footer>
  161. <!-- Le javascript
  162. ================================================== -->
  163. <!-- Placed at the end of the document so the pages load faster -->
  164. <script src="../asset/js/jquery.min.js"></script>
  165. <script type="text/javascript" src="../asset/js/echartsHome.js"></script>
  166. <script src="../asset/js/bootstrap.min.js"></script>
  167. <script src="../asset/js/echartsExample.js"></script>
  168. </body>
  169. </html>