index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>ECharts 关系图</title>
  6. <script src="js/jquery-1.8.3.min.js"></script>
  7. <script src="js/echarts.js"></script>
  8. </head>
  9. <body>
  10. <h1><select id="sel" style="height: 26px;margin-right: 10px;"><option value="Disease">诊断</option><option value="Symptom">症状</option><option value="Treat">治疗</option></select><input id="inputStr" style="height: 20px;"><input type="button" id="search" value="搜索" style="margin-left: 10px;"></h1>
  11. <div id="main" style="width:1000px;height:800px"></div>
  12. <script type="text/javascript">
  13. var myChart = echarts.init(document.getElementById('main'));
  14. var categories = [
  15. // {
  16. // "name":"中心词"
  17. // },
  18. // {
  19. // "name":"关系"
  20. // },
  21. // {
  22. // "name":"相关症状",
  23. // "symbol":"circle",
  24. // "symbolSize":28
  25. // },
  26. // {
  27. // "name":"发病部位",
  28. // "symbol":"circle",
  29. // "symbolSize":28
  30. // },
  31. // {
  32. // "name":"所属科室",
  33. // "symbol":"circle",
  34. // "symbolSize":28
  35. // },
  36. // {
  37. // "name":"检查",
  38. // "symbol":"circle",
  39. // "symbolSize":28
  40. // },
  41. // {
  42. // "name":"相关疾病",
  43. // "symbol":"circle",
  44. // "symbolSize":28
  45. // }
  46. ];
  47. var data = {"labelName":"Disease", "inputStr": "糖尿病"};
  48. $.ajax({
  49. type: "post",
  50. url: "http://localhost:5050/api/ltkg/kg/getTu",
  51. data: JSON.stringify(data),
  52. contentType: "application/json;charset=UTF-8",
  53. dataType: "json",
  54. success: function(res){
  55. console.log(res);
  56. var data = res.data;
  57. option.series[0].data = data.nodeList;
  58. option.series[0].links = data.linksList;
  59. option.series[0].categories = data.categoriesList;
  60. option.legend[0].data = data.categoriesList.slice(2, data.categoriesList.length);
  61. myChart.setOption(option);
  62. }
  63. });
  64. option = {
  65. // 图的标题
  66. title: {
  67. text: 'ECharts 关系图'
  68. },
  69. // 提示框的配置
  70. tooltip: {
  71. formatter: function (x) {
  72. return x.data.des;
  73. }
  74. },
  75. // 工具箱
  76. toolbox: {
  77. // 显示工具箱
  78. show: true,
  79. feature: {
  80. mark: {
  81. show: true
  82. },
  83. // 还原
  84. restore: {
  85. show: true
  86. },
  87. // 保存为图片
  88. saveAsImage: {
  89. show: true
  90. }
  91. }
  92. },
  93. legend: [{
  94. // selectedMode: 'single',
  95. data: categories.map(function (a) {
  96. return a.name;
  97. })
  98. }],
  99. series: [{
  100. type: 'graph', // 类型:关系图
  101. layout: 'force', //图的布局,类型为力导图
  102. // symbolSize: 40, // 调整节点的大小
  103. roam: true, // 是否开启鼠标缩放和平移漫游。默认不开启。如果只想要开启缩放或者平移,可以设置成 'scale' 或者 'move'。设置成 true 为都开启
  104. edgeSymbol: ['circle', 'arrow'],
  105. edgeSymbolSize: [2, 10],
  106. edgeLabel: {
  107. normal: {
  108. textStyle: {
  109. fontSize: 20
  110. }
  111. }
  112. },
  113. force: {
  114. repulsion: 200,
  115. edgeLength: [10,50],
  116. layoutAnimation: false
  117. },
  118. draggable: true,
  119. lineStyle: {
  120. normal: {
  121. width: 2,
  122. color: '#4b565b'
  123. }
  124. },
  125. edgeLabel: {
  126. normal: {
  127. show: true,
  128. formatter: function (x) {
  129. return x.data.value;
  130. }
  131. }
  132. },
  133. label: {
  134. normal: {
  135. show: true,
  136. formatter: function (x) {
  137. return x.data.label;
  138. },
  139. textStyle: {}
  140. }
  141. },
  142. // 数据
  143. data: [
  144. {
  145. "category":0,
  146. "label":"咳嗽",
  147. "name":0,
  148. "symbolSize":50
  149. },
  150. {
  151. "category":1,
  152. "label":"",
  153. "name":1,
  154. "symbol":"diamond",
  155. "symbolSize":10
  156. },
  157. {
  158. "category":2,
  159. "label":"点滴状便血",
  160. "name":2,
  161. "symbolSize":28
  162. },
  163. {
  164. "category":2,
  165. "label":"膀胱蓄热小便失禁",
  166. "name":3,
  167. "symbolSize":28
  168. },
  169. {
  170. "category":2,
  171. "label":"百日咳",
  172. "name":4,
  173. "symbolSize":28
  174. },
  175. {
  176. "category":2,
  177. "label":"大量胸水",
  178. "name":5,
  179. "symbolSize":28
  180. },
  181. {
  182. "category":1,
  183. "label":"",
  184. "name":6,
  185. "symbol":"diamond",
  186. "symbolSize":10
  187. },
  188. {
  189. "category":3,
  190. "label":"头部",
  191. "name":7,
  192. "symbol":"rect",
  193. "symbolSize":28
  194. },
  195. {
  196. "category":1,
  197. "label":"",
  198. "name":8,
  199. "symbol":"diamond",
  200. "symbolSize":10
  201. },
  202. {
  203. "category":4,
  204. "label":"五官科",
  205. "name":9,
  206. "symbol":"rect",
  207. "symbolSize":28
  208. },
  209. {
  210. "category":4,
  211. "label":"中西医结合科",
  212. "name":10,
  213. "symbol":"rect",
  214. "symbolSize":28
  215. },
  216. {
  217. "category":4,
  218. "label":"腹部损伤",
  219. "name":11,
  220. "symbolSize":28
  221. },
  222. {
  223. "category":4,
  224. "label":"内科",
  225. "name":12,
  226. "symbol":"rect",
  227. "symbolSize":28
  228. },
  229. {
  230. "category":1,
  231. "label":"",
  232. "name":13,
  233. "symbol":"diamond",
  234. "symbolSize":10
  235. },
  236. {
  237. "category":5,
  238. "label":"巨噬细胞或白细胞移动抑制试验mmit",
  239. "name":14,
  240. "symbolSize":28
  241. },
  242. {
  243. "category":5,
  244. "label":"浆膜腔积液",
  245. "name":15,
  246. "symbol":"rect",
  247. "symbolSize":28
  248. },
  249. {
  250. "category":5,
  251. "label":"浆膜腔积液葡萄糖",
  252. "name":16,
  253. "symbol":"rect",
  254. "symbolSize":28
  255. },
  256. {
  257. "category":5,
  258. "label":"结核菌素试验(OT,PPD)",
  259. "name":17,
  260. "symbol":"rect",
  261. "symbolSize":28
  262. },
  263. {
  264. "category":1,
  265. "label":"",
  266. "name":18,
  267. "symbol":"diamond",
  268. "symbolSize":10
  269. },
  270. {
  271. "category":6,
  272. "label":"HIV相关呼吸道感染",
  273. "name":19,
  274. "symbolSize":28
  275. },
  276. {
  277. "category":6,
  278. "label":"热带型肺嗜酸性粒细胞肺炎",
  279. "name":20,
  280. "symbolSize":28
  281. }
  282. ],
  283. links: [
  284. {
  285. "source":0,
  286. "target":1,
  287. "value":"相关症状"
  288. },
  289. {
  290. "source":1,
  291. "target":2,
  292. "value":""
  293. },
  294. {
  295. "source":1,
  296. "target":3,
  297. "value":""
  298. },
  299. {
  300. "source":1,
  301. "target":4,
  302. "value":""
  303. },
  304. {
  305. "source":1,
  306. "target":5,
  307. "value":""
  308. },
  309. {
  310. "source":0,
  311. "target":6,
  312. "value":"发病部位"
  313. },
  314. {
  315. "source":6,
  316. "target":7,
  317. "value":""
  318. },
  319. {
  320. "source":0,
  321. "target":8,
  322. "value":"所属科室"
  323. },
  324. {
  325. "source":8,
  326. "target":9,
  327. "value":""
  328. },
  329. {
  330. "source":8,
  331. "target":10,
  332. "value":""
  333. },
  334. {
  335. "source":8,
  336. "target":11,
  337. "value":""
  338. },
  339. {
  340. "source":8,
  341. "target":12,
  342. "value":""
  343. },
  344. {
  345. "source":0,
  346. "target":13,
  347. "value":"检查"
  348. },
  349. {
  350. "source":13,
  351. "target":14,
  352. "value":""
  353. },
  354. {
  355. "source":13,
  356. "target":15,
  357. "value":""
  358. },
  359. {
  360. "source":13,
  361. "target":16,
  362. "value":""
  363. },
  364. {
  365. "source":13,
  366. "target":17,
  367. "value":""
  368. },
  369. {
  370. "source":0,
  371. "target":18,
  372. "value":"相关疾病"
  373. },
  374. {
  375. "source":18,
  376. "target":19,
  377. "value":""
  378. },
  379. {
  380. "source":18,
  381. "target":20,
  382. "value":""
  383. }
  384. ],
  385. categories: categories,
  386. }]
  387. };
  388. $("#search").click(function() {
  389. var data = {};
  390. data.labelName = $("#sel").val();
  391. data.inputStr = $("#inputStr").val().trim();
  392. $.ajax({
  393. type: "post",
  394. url: "/kg/getTu",
  395. data: JSON.stringify(data),
  396. contentType: "application/json;charset=UTF-8",
  397. dataType: "json",
  398. success: function(res){
  399. console.log(res);
  400. var data = res.data;
  401. option.series[0].data = data.nodeList;
  402. option.series[0].links = data.linksList;
  403. option.series[0].categories = data.categoriesList;
  404. option.legend[0].data = data.categoriesList.slice(2, data.categoriesList.length);
  405. myChart.setOption(option);
  406. }
  407. });
  408. });
  409. myChart.on('click', function (param){
  410. console.log('param---->', param); // 打印出param, 可以看到里边有很多参数可以使用
  411. //获取节点点击的数组序号
  412. var arrayIndex = param.dataIndex;
  413. if (param.dataType == 'node' && !param.data.symbol) {
  414. var data = {};
  415. // data.labelName = $("#sel").val();
  416. data.labelName = param.data.type;
  417. data.inputStr = param.data.label.trim();
  418. $.ajax({
  419. type: "post",
  420. url: "/kg/getTu",
  421. data: JSON.stringify(data),
  422. contentType: "application/json;charset=UTF-8",
  423. dataType: "json",
  424. success: function(res){
  425. console.log(res);
  426. var data = res.data;
  427. option.series[0].data = data.nodeList;
  428. option.series[0].links = data.linksList;
  429. option.series[0].categories = data.categoriesList;
  430. option.legend[0].data = data.categoriesList.slice(2, data.categoriesList.length);
  431. myChart.setOption(option);
  432. }
  433. });
  434. }
  435. });
  436. </script>
  437. </body>
  438. </html>