Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

344
Vistas
d3.csv() function from D3.js library works but gives a blank error

I use d3.CSV() function, and it works. Nevertheless, it gives a blank error! I have to figure out this problem as it may cause complications later.

CSV file:

Food,Rating
Pizza,90
Ice Cream,92
Spaghetti,85
Tuna Salad,75

Script:

<script>
                       
        d3.csv("food.csv", function(error,data) {

            if (error) {
                console.log("error messages: ", error)
            } else  {
                console.log(data)
            }
           
        })
       
   </script>

Output:

test.html:17 error messages:  {Food: 'Pizza', Rating: '90'}
test.html:17 error messages:  {Food: 'Ice Cream', Rating: '92'}
test.html:17 error messages:  {Food: 'Spaghetti', Rating: '85'}
test.html:17 error messages:  {Food: 'Tuna Salad', Rating: '75'}

Line 17 in the HTML file is:

console.log("error messages: ", error)

Update Aug 15, 2022

D3.js version: I got this link from the D3.js website

https://d3js.org/d3.v7.min.js

Based on Dan's suggestion, I tried the following block of code:

d3.csv("food.csv").then(data => {
      console.log(data)
   }).catch(error => {
      console.error(error)
})

I get results without any error message. Now, I want to induce an error to check on error reporting, I change food.csv to food1.csv. I don't get results, but there is no error message. I get all the HTML elements listed in the console like the old fashion code's output.

I tried the following code with the wrong name for the CSV file to induce an error and see if I could get any error message:

d3.csv("food1.csv").then(data => {
      console.log(data)
   }).catch(error => {
      console.log("There is an error: ",error)
   })

Same as the old fashion code, instead of an error message, I get all the HTML elements of the page in an array as the output in the console.

How can we get a decent error message from d3.csv()?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The way that you are reading the file was deprecated in D3 version 5. In more recent versions of D3, you would do

d3.csv("food.csv").then(data => {
  console.log(data);
});

You can find the documentation here.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda