graph created by arbor not shown

44 Views Asked by At

I want to use arbor to creating graph in an HTML file. I write codes bellow but nothing show in canvas

<html>

<head>
  <title>graph</title>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" src="arbor.js"></script>
  <script type="text/javascript" src="graphics.js"></script>
  <script type="text/javascript" src="renderer.js"></script>
</head>

<body>
  <canvas id="viewport" width="800" height="600" style="background-color: yellow"></canvas>
  <script src="jquery.js"></script>

  <script language="javascript" type="text/javascript">
    var sys = arbor.ParticleSystem(1000, 400, 1);
    sys.parameters({
      gravity: true
    });
    sys.renderer = Renderer("#viewport");
    var data = {
      nodes: {
        animals: {
          'color': 'red',
          'shape': 'dot',
          'label': 'Animals'
        },
        dog: {
          'color': 'green',
          'shape': 'dot',
          'label': 'dog'
        },
        cat: {
          'color': 'blue',
          'shape': 'dot',
          'label': 'cat'
        }
      },
      edges: {
        animals: {
          dog: {},
          cat: {}
        }
      }
    };
    sys.graft(data);
  </script>

  <!--script src="test.js"></script-->
</body>

</html>

after running these codes nothing show in viewpoint canvas.what is the problem?

1

There are 1 best solutions below

2
On

except for jquery being loaded twice, your code looks fine. So the problem might be with the files, Just check if your js files are in the same directory as your html. The following code works for me

<!DOCTYPE html>
<html>
<head>
    <title>graph</title>
    <script src="jquery.js"></script>
    <script src="arbor.js"></script>
    <script src="graphics.js"></script>
    <script src="renderer.js"></script>
</head>
<body>
    <canvas id="viewport" width="800" height="600"></canvas>
    <script language="javascript" type="text/javascript">
        var sys = arbor.ParticleSystem(1000, 400, 1);
        sys.parameters({
            gravity: true
        });
        sys.renderer = Renderer("#viewport");
        var data = {
            nodes: {
                animals: {
                    'color': 'red',
                    'shape': 'dot',
                    'label': 'Animals'
                },
                dog: {
                    'color': 'green',
                    'shape': 'dot',
                    'label': 'dog'
                },
                cat: {
                    'color': 'blue',
                    'shape': 'dot',
                    'label': 'cat'
                }
            },
            edges: {
                animals: {
                    dog: {},
                    cat: {}
                }
            }
        };
        sys.graft(data);
    </script>
</body>
</html>