force1.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. option = {
  36. title : {
  37. text: '人物关系:乔布斯',
  38. subtext: '数据来自人立方',
  39. x:'right',
  40. y:'bottom'
  41. },
  42. tooltip : {
  43. trigger: 'item',
  44. formatter: '{a} : {b}'
  45. },
  46. toolbox: {
  47. show : true,
  48. feature : {
  49. restore : {show: true},
  50. magicType: {show: true, type: ['force', 'chord']},
  51. saveAsImage : {show: true}
  52. }
  53. },
  54. legend: {
  55. x: 'left',
  56. data:['家人','朋友']
  57. },
  58. series : [
  59. {
  60. type:'force',
  61. name : "人物关系",
  62. ribbonType: false,
  63. categories : [
  64. {
  65. name: '人物'
  66. },
  67. {
  68. name: '家人'
  69. },
  70. {
  71. name:'朋友'
  72. }
  73. ],
  74. itemStyle: {
  75. normal: {
  76. label: {
  77. show: true,
  78. textStyle: {
  79. color: '#333'
  80. }
  81. },
  82. nodeStyle : {
  83. brushType : 'both',
  84. borderColor : 'rgba(255,215,0,0.4)',
  85. borderWidth : 1
  86. },
  87. linkStyle: {
  88. type: 'curve'
  89. }
  90. },
  91. emphasis: {
  92. label: {
  93. show: false
  94. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  95. },
  96. nodeStyle : {
  97. //r: 30
  98. },
  99. linkStyle : {}
  100. }
  101. },
  102. useWorker: false,
  103. minRadius : 15,
  104. maxRadius : 25,
  105. gravity: 1.1,
  106. scaling: 1.1,
  107. roam: 'move',
  108. nodes:[
  109. {category:0, name: '乔布斯', value : 10, label: '乔布斯\n(主要)'},
  110. {category:1, name: '丽萨-乔布斯',value : 2},
  111. {category:1, name: '保罗-乔布斯',value : 3},
  112. {category:1, name: '克拉拉-乔布斯',value : 3},
  113. {category:1, name: '劳伦-鲍威尔',value : 7},
  114. {category:2, name: '史蒂夫-沃兹尼艾克',value : 5},
  115. {category:2, name: '奥巴马',value : 8},
  116. {category:2, name: '比尔-盖茨',value : 9},
  117. {category:2, name: '乔纳森-艾夫',value : 4},
  118. {category:2, name: '蒂姆-库克',value : 4},
  119. {category:2, name: '龙-韦恩',value : 1},
  120. ],
  121. links : [
  122. {source : '丽萨-乔布斯', target : '乔布斯', weight : 1, name: '女儿'},
  123. {source : '保罗-乔布斯', target : '乔布斯', weight : 2, name: '父亲'},
  124. {source : '克拉拉-乔布斯', target : '乔布斯', weight : 1, name: '母亲'},
  125. {source : '劳伦-鲍威尔', target : '乔布斯', weight : 2},
  126. {source : '史蒂夫-沃兹尼艾克', target : '乔布斯', weight : 3, name: '合伙人'},
  127. {source : '奥巴马', target : '乔布斯', weight : 1},
  128. {source : '比尔-盖茨', target : '乔布斯', weight : 6, name: '竞争对手'},
  129. {source : '乔纳森-艾夫', target : '乔布斯', weight : 1, name: '爱将'},
  130. {source : '蒂姆-库克', target : '乔布斯', weight : 1},
  131. {source : '龙-韦恩', target : '乔布斯', weight : 1},
  132. {source : '克拉拉-乔布斯', target : '保罗-乔布斯', weight : 1},
  133. {source : '奥巴马', target : '保罗-乔布斯', weight : 1},
  134. {source : '奥巴马', target : '克拉拉-乔布斯', weight : 1},
  135. {source : '奥巴马', target : '劳伦-鲍威尔', weight : 1},
  136. {source : '奥巴马', target : '史蒂夫-沃兹尼艾克', weight : 1},
  137. {source : '比尔-盖茨', target : '奥巴马', weight : 6},
  138. {source : '比尔-盖茨', target : '克拉拉-乔布斯', weight : 1},
  139. {source : '蒂姆-库克', target : '奥巴马', weight : 1}
  140. ]
  141. }
  142. ]
  143. };
  144. var ecConfig = require('echarts/config');
  145. function focus(param) {
  146. var data = param.data;
  147. var links = option.series[0].links;
  148. var nodes = option.series[0].nodes;
  149. if (
  150. data.source !== undefined
  151. && data.target !== undefined
  152. ) { //点击的是边
  153. var sourceNode = nodes.filter(function (n) {return n.name == data.source})[0];
  154. var targetNode = nodes.filter(function (n) {return n.name == data.target})[0];
  155. console.log("选中了边 " + sourceNode.name + ' -> ' + targetNode.name + ' (' + data.weight + ')');
  156. } else { // 点击的是点
  157. console.log("选中了" + data.name + '(' + data.value + ')');
  158. }
  159. }
  160. myChart.on(ecConfig.EVENT.CLICK, focus)
  161. myChart.on(ecConfig.EVENT.FORCE_LAYOUT_END, function () {
  162. console.log(myChart.chart.force.getPosition());
  163. });
  164. </textarea>
  165. </div><!--/.well -->
  166. </div><!--/span-->
  167. <div id="graphic" class="col-md-8">
  168. <div id="main" class="main"></div>
  169. <div>
  170. <button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
  171. <span class="text-primary">切换主题</span>
  172. <select id="theme-select"></select>
  173. <span id='wrong-message' style="color:red"></span>
  174. </div>
  175. </div><!--/span-->
  176. </div><!--/row-->
  177. </div><!--/.fluid-container-->
  178. <footer id="footer"></footer>
  179. <!-- Le javascript
  180. ================================================== -->
  181. <!-- Placed at the end of the document so the pages load faster -->
  182. <script src="../asset/js/jquery.min.js"></script>
  183. <script type="text/javascript" src="../asset/js/echartsHome.js"></script>
  184. <script src="../asset/js/bootstrap.min.js"></script>
  185. <script src="../asset/js/echartsExample.js"></script>
  186. </body>
  187. </html>