Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsnetworkx.js:5 Uncaught TypeError: Cannot read property 'force' of undefined #62

Open
ScientiaEtVeritas opened this issue Jul 26, 2016 · 11 comments

Comments

@ScientiaEtVeritas
Copy link

ScientiaEtVeritas commented Jul 26, 2016

Hi, I'm trying to draw the graph, but always get this error:
jsnetworkx.js:5 Uncaught TypeError: Cannot read property 'force' of undefined

Even if I try sth. like this:
` G = new jsnx.Graph();

    G.addNode(1);
    G.addNode(2);

    G.addEdge(1,2);


    jsnx.draw(G, {
      element: '#canvas',
      withLabels: false
    });`

Does someone have an idea what's the reason for this?

D3 is included.

Thanks in advance.

@juhojo
Copy link

juhojo commented Dec 5, 2016

Hey, I was experiencing the same issue and downgrading d3 version was the solution for me.
Try changing you d3 script to this one:
<script src="http://d3js.org/d3.v3.min.js"></script>

@jeffzemla
Copy link

Downgrading d3 resulted in a different error for me:

Uncaught TypeError: Cannot read property 'getComputedStyle' of null

I tried implementing ScientiaEtVeritas's example and also some examples from the jsnetworkx.org page.

@juhojo
Copy link

juhojo commented Mar 5, 2017

Are you certain that you did pass a correct element to the jsnx.draw()- function? getComputedStyle method is used to

give the values of all the CSS properties of an element after applying the active stylesheets and resolving any basic computation those values may contain. MDN - Mozilla Foundation

so it appears to me that the canvas element you have created in your HTML DOM does not have an id canvas, therefore resulting in the compile error.

I cannot provide more suggestions, because I have not yet received a similar error.

@revosys
Copy link

revosys commented May 17, 2017

i m facing same problem...

@bigbasti
Copy link

Downgrading d3 also solved this issue for me

@revosys
Copy link

revosys commented May 17, 2017

My code is simple.... but still this is the issue...

<script src="//d3js.org/d3.v3.js"></script>
<script src="js/jsnetworkx.js"></script>
<script>

var G = new jsnx.Graph();
G.addNodesFrom([
    [1, {color: 'red'}],
    [2, {color: 'green'}],
    [3, {color: 'white'}]
]);
 
G.addEdgesFrom([[1,2], [1,3]]);
 
// `jsnx.draw` accept a graph and configuration object
jsnx.draw(G, {
  element: '#canvas',
  withLabels: true,
  nodeStyle: {
      fill: function(d) {
          return d.data.color;
      }
  }
});

</script>

<div id="canvas" class="span9"></div>

Error is Uncaught TypeError: Cannot read property 'getComputedStyle' of null
at Array.d3_selectionPrototype.style (d3.v3.js:740)
at Object.i [as draw] (jsnetworkx.js:5)

@bigbasti
Copy link

just a wild guess here: shouldn't you declare the div you want to draw in BEFORE drawing on it?
(move the div before the script)

@revosys
Copy link

revosys commented May 17, 2017

thanks for your reply.... ITS WORKING....:) Thanks

@bigbasti
Copy link

i just tried your code - got the same error - moved the div above the script tag and everything ran fine

@revosys
Copy link

revosys commented May 17, 2017

Yes.... Some time over load work can make you behave like idiot...:)

@snipercup
Copy link

I have the same problem. I can downgrade to d3 v3, but then I get the error:
jsnetworkx.js:5 Uncaught Error: D3 requried for draw()

im using <script src="http://d3js.org/d3.v3.min.js"></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants