1

I have data in a .csv file that I am trying to display using D3. My script inside the head tag has a function:

        function show(data) {
            console.log(data[0]);
            d3.select("body")
                .selectAll("p")
                .data(data)
                .enter()
                .append("p")
                .text(function(d) { return d.price} )                   
        }

In the body of the page inside a script tag I have:

    d3.csv('simple5.csv', show)

The file simple5.csv is:

name, price
a, 5
b, 10
c, 15
d, 20
e, 25
f, 30
g, 35

While the console.log function shows me the data, I am unable to see the data in the HTML page. I have tried using the d3.csv.parse and the d3.cd.parseRows functions, but then I get an error: "text.charCodeAt is not a function".

Nikhil
  • 3,711
  • 8
  • 32
  • 43
Ravi
  • 41
  • 1
  • 3

1 Answers1

0

If you remove your .text() function, you can see that the p tags are getting created. Therefore, your csv format is incorrect. When I changed it to the following, it started working : name,price

a,5
b,10
c,15
d,20
e,25
f,30
g,35

Please try.

Nikhilesh K V
  • 1,480
  • 13
  • 20