score:1
Accepted answer
This is due to the asynchronous nature of javascript. The blocks of code you write do not get evaluated "in order" as you might expect. Basically, anything that uses the d3.csv
call HAS to be within that block:
d3.csv("epochStats.csv", function(d) {
console.log(d.length);
maxEpochs = d.length;
console.log(maxEpochs);
// anything else that uses the value of maxEpochs, or reads the file data, etc....
});
console.log(maxEpochs); <-- This could be evaluated before the above csv block.
Source: stackoverflow.com
Related Query
- javascript and d3.js variable scope: variable resets outside of function call
- D3, javascript function scope with setInterval and clearInterval and event handler
- writing a Javascript function outside of scope to fire inside the scope
- D3.js - Load data from CSV file and use it outside function call
- Javascript library d3 call function
- variable scope in d3 javascript
- Probability density function with javascript d3 and dc
- Call JavaScript function from SVG file
- Create external JavaScript file and call it on HTML5 canvas
- d3 javascript click function call
- D3 V6 and JavaScript - GeoJSON fill is "spilling" outside of path
- Javascript button onclick event to call function inside function in module
- How do I make my text keep the variable number and not the reference in javascript D3?
- D3 JavaScript return data value plus variable from anonymous function
- Constraints on slider jquery + callng javascript function at page loadto call javascript function
- Javascript function call in Handlebar
- AngularJS and D3 - JavaScript RangeError: Maximum call stack size exceeded in recursion
- How to call javascript function from D3 button
- How to import a package and call the function in angular?
- How do I access the output of JavaScript function outside the function?
- Weird behaviour related to scope in javascript and d3.js
- Variable scope in d3 when callback is an event function
- d3js not having the same behaviour within and outside a function
- How to call a function a fixed number of times after fixed intervals in javascript
- Issues with Javascript closures and scope
- Put D3 code into a function and call
- trying to call a named function with async javascript then
- Call custom made function from svg element using AngularJs and D3.js
- access var outside function scope
- Can I call a JavaScript function on an iFrame or similar widget from Python?
More Query from same tag
- crossfilter | animate through date range
- D3.js Mouse events between different SVG groups
- How can I put a new timeline chart for d3 on bl-ocks.org
- Error when passing JSON data to d3.json
- How to modify d3js fisheye distortion so that it will support radius
- d3 pie: redraw label on path change
- Simple transition between datasets on click
- JS: Working with Sliders
- Why is D3.js data only available to child nodes when enter() is chained, not invoked separately
- How to insert a header in csv object data for manage with d3.js
- d3v4 Lollipop chart - refactored conversion - static
- Axis not ligning up to bars
- Time slider to move automatically using setInterval()
- D3 Pie Error: Invalid value for <text> attribute transform="translate(NaN,NaN)"
- Saving json file on server using JavaScript
- Based on tick values, how can I change width of my chart
- d3 Zoomable Treemap - Dynamic Text Width per Parent Width
- "Property _ does not exist on _ type" D3.js typescript errors in Ionic 2 project
- How to get the total number of rows with particular value in json file in d3.js
- d3.js - draw stations and path on google map
- How can I make convex hulls of multiple group network nodes in D3.js
- svg viewbox using d3.js: space above graph is still too large
- d3-force Make nodes move slower on position update
- Transition In D3 Bar Graph Not Working
- Collapsible Radial Tidy Tree found in ObservableHQ is not collapsing after mouse click if I use d3 v6 instead of d3 v5
- Use both "d3.event.preventDefault" and "d3.event.which"
- Converting ctree output into JSON Format (for D3 tree layout)
- unable to access a .csv file using java script in html
- D3 Sankey Diagram: Changing Node Position
- How to handle data using D3?