d3. Calling a csv url from an array javascript

Pedro Ihnen Rendić

I'm new at this. Im trying to make a simple interactive chart using jaavascript. The idea is that when I change the values in the selector, the chart change the data is using.

However, I´m having troubles with the data switching. The data come´s frome different urls. Those urls are in a CSV file. My code extracts the urls from th CSV file and makes an array. Then it proceed to call the CSV file from the adequate element of the array. Simplifying the code:

functionThatReturnsArray(){
d3.csv("http//URL.COM", function(){
SomeMoreCode;
return ArrayOfStrings
};)
}

A = functionThatReturnsArray();

MoreCode;

//For example, the first value from A is selected
d3.csv(A[0], function(error, data) {
MoreCode;
})

The problem is that it seems that this isn´t a valid input to d3.csv, because it doesn´t work. I don´t know if i´m missing something or it just can´t be done this way.

I searched and it might be from the fact that d3.csv is an asynchronous method, but I´m not sure if that´s the problem.

Any suggestion will be apreciated

bumbeishvili

Your first CSV data is loading asynchronously, so this function will not return anything

functionThatReturnsArray(){
   d3.csv("http//URL.COM", function(){
       SomeMoreCode;
       return ArrayOfStrings
   };)
}

You can put following code in function

function processArray(A){

   MoreCode;

   //For example, the first value from A is selected
   d3.csv(A[0], function(error, data) {
   MoreCode;
  })
}

and invoke this function in first csv loading callback

 functionThatReturnsArray(){
       d3.csv("http//URL.COM", function(){
           SomeMoreCode;
           processArray(ArrayOfStrings) //add this
       };)
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Copy data from csv into array in D3

From Dev

Django calling url in javascript

From Dev

D3 - Loading data from a second CSV

From Dev

Interrupting calling data-url-action in Razor View from javascript

From Dev

Rendering D3 data from CSV

From Dev

Displaying images from a csv with d3

From Dev

Generate a csv file from a javascript array of objects

From Dev

d3 importing csv file to array

From Dev

NodeJs Javascript Calling a Function Dynamically From an Array

From Dev

Loading in a CSV file as a Map (D3 and JavaScript)

From Dev

Calling array from the module in Python 3

From Dev

Calling each value of an array or csv as a parameter in a url

From Dev

D3 : get value from the array

From Dev

Calling javascript Service/Method from array object

From Dev

Sum an entire csv column to show total with d3 javascript

From Dev

d3 drawing polygons from a csv

From Dev

streamgraph from .csv file in D3

From Dev

javascript d3 get the biggest value from a multi-nested array/object dataset

From Dev

Calling string from array using loop after onclick function [javascript]

From Dev

Javascript D3 graphs, sorting an array

From Dev

Two csv http URL data same chart in D3

From Dev

JavaScript , D3 bar graph error using CSV

From Dev

Javascript: calling function within D3 from another file

From Dev

d3 retrieval of a csv file returns Nan in the javascript console

From Dev

D3 dashboard chart data bind from json or csv

From Dev

CSV to HTML table using d3 and an external javascript file

From Dev

Calling and displaying image from a nested array using javascript

From Dev

Calling a URL handler from javascript

From Dev

Calling a URL on receiving an event from a button click using JavaScript

Related Related

HotTag

Archive