force2.html 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <script src="lib/jquery.min.js"></script>
  7. <script src="lib/dat.gui.min.js"></script>
  8. </head>
  9. <body>
  10. <style>
  11. html, body, #main {
  12. width: 100%;
  13. height: 100%;
  14. margin: 0;
  15. }
  16. </style>
  17. <div id="main"></div>
  18. <script>
  19. require([
  20. 'echarts',
  21. 'extension/dataTool/gexf',
  22. 'echarts/chart/graph',
  23. 'echarts/component/title',
  24. 'echarts/component/legend',
  25. 'echarts/component/geo',
  26. 'echarts/component/tooltip',
  27. 'echarts/component/visualMap'
  28. ], function (echarts, gexf) {
  29. var chart = echarts.init(document.getElementById('main'), null, {
  30. renderer: 'canvas'
  31. });
  32. $.get('./data/les-miserables.gexf', function (xml) {
  33. var graph = gexf.parse(xml);
  34. var categories = [];
  35. for (var i = 0; i < 9; i++) {
  36. categories[i] = {
  37. name: '类目' + i
  38. };
  39. }
  40. graph.nodes.forEach(function (node) {
  41. node.itemStyle = null;
  42. node.symbolSize = 10;
  43. node.value = node.symbolSize;
  44. node.label = {
  45. normal: {
  46. show: node.symbolSize > 30
  47. }
  48. };
  49. node.category = node.attributes['modularity_class'];
  50. node.x = node.y = null;
  51. });
  52. chart.setOption({
  53. legend: [{
  54. // selectedMode: 'single',
  55. data: categories.map(function (a) {
  56. return a.name;
  57. })
  58. }],
  59. animationDurationUpdate: 1500,
  60. animationEasingUpdate: 'quinticInOut',
  61. series : [
  62. {
  63. name: 'Les Miserables',
  64. type: 'graph',
  65. layout: 'force',
  66. data: graph.nodes,
  67. links: graph.links,
  68. categories: categories,
  69. animation: false,
  70. roam: true,
  71. draggable: true,
  72. edgeSymbol: ['none', 'arrow'],
  73. edgeSymbolSize: 5,
  74. force: {
  75. repulsion: [0, 100]
  76. },
  77. label: {
  78. normal: {
  79. position: 'right'
  80. }
  81. }
  82. }
  83. ]
  84. });
  85. });
  86. });
  87. </script>
  88. </body>
  89. </html>