Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

345
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda