force2.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. force: {
  73. repulsion: 100
  74. },
  75. label: {
  76. normal: {
  77. position: 'right'
  78. }
  79. }
  80. }
  81. ]
  82. });
  83. });
  84. });
  85. </script>
  86. </body>
  87. </html>