125Echarts - 关系图(Force Layout)

简介: 125Echarts - 关系图(Force Layout)
效果图

源代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="js/echarts.min.js"></script>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="dist/extension/dataTool.js"></script>
  </head>
  <body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="width: 600px;height:400px;"></div>
    <script type="text/javascript">
      // 基于准备好的dom,初始化echarts实例
      var myChart = echarts.init(document.getElementById('main'));
      var option;
      function createNodes(count) {
        var nodes = [];
        for(var i = 0; i < count; i++) {
          nodes.push({
            id: i
          });
        }
        return nodes;
      }
      function createEdges(count) {
        var edges = [];
        if(count === 2) {
          return [
            [0, 1]
          ];
        }
        for(var i = 0; i < count; i++) {
          edges.push([i, (i + 1) % count]);
        }
        return edges;
      }
      var datas = [];
      for(var i = 0; i < 16; i++) {
        datas.push({
          nodes: createNodes(i + 2),
          edges: createEdges(i + 2)
        });
      }
      option = {
        series: datas.map(function(item, idx) {
          return {
            type: 'graph',
            layout: 'force',
            animation: false,
            data: item.nodes,
            left: (idx % 4) * 25 + '%',
            top: Math.floor(idx / 4) * 25 + '%',
            width: '25%',
            height: '25%',
            force: {
              // initLayout: 'circular'
              // gravity: 0
              repulsion: 60,
              edgeLength: 2
            },
            edges: item.edges.map(function(e) {
              return {
                source: e[0],
                target: e[1]
              };
            })
          };
        })
      };
      myChart.setOption(option);
    </script>
  </body>
</html>
目录
相关文章
|
11月前
130Echarts - 关系图(Graph Webkit Dep)
130Echarts - 关系图(Graph Webkit Dep)
40 0
|
6月前
|
JavaScript
echarts_自定义graph关系图
echarts_自定义graph关系图
127 0
131Echarts - 关系图(Calendar Graph)
131Echarts - 关系图(Calendar Graph)
46 0
|
11月前
|
JSON 数据格式
echarts关系图
echarts关系图
76 0
269Echarts - GL 关系图(1w 节点 2w7 边的NPM 依赖图)
269Echarts - GL 关系图(1w 节点 2w7 边的NPM 依赖图)
89 0
268Echarts - GL 关系图(GraphGL - Large Internet)
268Echarts - GL 关系图(GraphGL - Large Internet)
118 0
|
异构计算
267Echarts - GL 关系图(GraphGL GPU Layout)
267Echarts - GL 关系图(GraphGL GPU Layout)
94 0
207Echarts - 数据集(Series Layout By Column or Row)
207Echarts - 数据集(Series Layout By Column or Row)
48 0
129Echarts - 关系图(Simple Graph)
129Echarts - 关系图(Simple Graph)
48 0
128Echarts - 关系图(NPM Dependencies)
128Echarts - 关系图(NPM Dependencies)
72 0

热门文章

最新文章

下一篇
无影云桌面