force.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. symbol: 'diamond'
  70. },
  71. {
  72. name:'朋友'
  73. }
  74. ],
  75. itemStyle: {
  76. normal: {
  77. label: {
  78. show: true,
  79. textStyle: {
  80. color: '#333'
  81. }
  82. },
  83. nodeStyle : {
  84. brushType : 'both',
  85. borderColor : 'rgba(255,215,0,0.4)',
  86. borderWidth : 1
  87. }
  88. },
  89. emphasis: {
  90. label: {
  91. show: false
  92. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  93. },
  94. nodeStyle : {
  95. //r: 30
  96. },
  97. linkStyle : {}
  98. }
  99. },
  100. minRadius : 15,
  101. maxRadius : 25,
  102. gravity: 1.1,
  103. scaling: 1.2,
  104. draggable: false,
  105. linkSymbol: 'arrow',
  106. steps: 10,
  107. coolDown: 0.9,
  108. //preventOverlap: true,
  109. nodes:[
  110. {
  111. category:0, name: '乔布斯', value : 10,
  112. symbol: 'image://http://www.damndigital.com/wp-content/uploads/2010/12/steve-jobs.jpg',
  113. symbolSize: 30,
  114. draggable: true,
  115. itemStyle: {
  116. normal: {
  117. label: {
  118. position: 'right',
  119. textStyle: {
  120. color: 'black'
  121. }
  122. }
  123. }
  124. }
  125. },
  126. {category:1, name: '丽萨-乔布斯',value : 2},
  127. {category:1, name: '保罗-乔布斯',value : 3},
  128. {category:1, name: '克拉拉-乔布斯',value : 3},
  129. {category:1, name: '劳伦-鲍威尔',value : 7},
  130. {category:2, name: '史蒂夫-沃兹尼艾克',value : 5},
  131. {category:2, name: '奥巴马',value : 8},
  132. {category:2, name: '比尔-盖茨',value : 9},
  133. {category:2, name: '乔纳森-艾夫',value : 4},
  134. {category:2, name: '蒂姆-库克',value : 4},
  135. {category:2, name: '龙-韦恩',value : 1},
  136. ],
  137. links : [
  138. {source : '丽萨-乔布斯', target : '乔布斯', weight : 1, name: '女儿', itemStyle: {
  139. normal: {
  140. width: 1.5,
  141. color: 'red'
  142. }
  143. }},
  144. {source : '乔布斯', target : '丽萨-乔布斯', weight : 1, name: '父亲', itemStyle: {
  145. normal: { color: 'red' }
  146. }},
  147. {source : '保罗-乔布斯', target : '乔布斯', weight : 2, name: '父亲'},
  148. {source : '克拉拉-乔布斯', target : '乔布斯', weight : 1, name: '母亲'},
  149. {source : '劳伦-鲍威尔', target : '乔布斯', weight : 2},
  150. {source : '史蒂夫-沃兹尼艾克', target : '乔布斯', weight : 3, name: '合伙人'},
  151. {source : '奥巴马', target : '乔布斯', weight : 1},
  152. {source : '比尔-盖茨', target : '乔布斯', weight : 6, name: '竞争对手'},
  153. {source : '乔纳森-艾夫', target : '乔布斯', weight : 1, name: '爱将'},
  154. {source : '蒂姆-库克', target : '乔布斯', weight : 1},
  155. {source : '龙-韦恩', target : '乔布斯', weight : 1},
  156. {source : '克拉拉-乔布斯', target : '保罗-乔布斯', weight : 1},
  157. {source : '奥巴马', target : '保罗-乔布斯', weight : 1},
  158. {source : '奥巴马', target : '克拉拉-乔布斯', weight : 1},
  159. {source : '奥巴马', target : '劳伦-鲍威尔', weight : 1},
  160. {source : '奥巴马', target : '史蒂夫-沃兹尼艾克', weight : 1},
  161. {source : '比尔-盖茨', target : '奥巴马', weight : 6},
  162. {source : '比尔-盖茨', target : '克拉拉-乔布斯', weight : 1},
  163. {source : '蒂姆-库克', target : '奥巴马', weight : 1}
  164. ]
  165. }
  166. ]
  167. };
  168. var ecConfig = require('echarts/config');
  169. function focus(param) {
  170. var data = param.data;
  171. var links = option.series[0].links;
  172. var nodes = option.series[0].nodes;
  173. if (
  174. data.source != null
  175. && data.target != null
  176. ) { //点击的是边
  177. var sourceNode = nodes.filter(function (n) {return n.name == data.source})[0];
  178. var targetNode = nodes.filter(function (n) {return n.name == data.target})[0];
  179. console.log("选中了边 " + sourceNode.name + ' -> ' + targetNode.name + ' (' + data.weight + ')');
  180. } else { // 点击的是点
  181. console.log("选中了" + data.name + '(' + data.value + ')');
  182. }
  183. }
  184. myChart.on(ecConfig.EVENT.CLICK, focus)
  185. myChart.on(ecConfig.EVENT.FORCE_LAYOUT_END, function () {
  186. console.log(myChart.chart.force.getPosition());
  187. });
  188. </textarea>
  189. </div><!--/.well -->
  190. </div><!--/span-->
  191. <div id="graphic" class="col-md-8">
  192. <div id="main" class="main"></div>
  193. <div>
  194. <button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
  195. <span class="text-primary">切换主题</span>
  196. <select id="theme-select"></select>
  197. <span id='wrong-message' style="color:red"></span>
  198. </div>
  199. </div><!--/span-->
  200. </div><!--/row-->
  201. </div><!--/.fluid-container-->
  202. <footer id="footer"></footer>
  203. <!-- Le javascript
  204. ================================================== -->
  205. <!-- Placed at the end of the document so the pages load faster -->
  206. <script src="../asset/js/jquery.min.js"></script>
  207. <script type="text/javascript" src="../asset/js/echartsHome.js"></script>
  208. <script src="../asset/js/bootstrap.min.js"></script>
  209. <script src="../asset/js/echartsExample.js"></script>
  210. </body>
  211. </html>