1

I'm reading 'Interactive Data Visualization for the Web' and in chapter 16 I'm having an issue with the code below.

As far as I know, d3.request has been deprecated, so I'm wondering how I can write the equivalent of this function. Is it with fetch?

d3.request("vehicle_sales_data.csv")
.mimeType("text/csv")
.get(function(response) {
    var rows = d3.csvParseRows(response.responseText); ...}

Thanks.

ksav
  • 20,015
  • 6
  • 46
  • 66
  • Possible duplicate of [How to read in CSV with d3 v4?](https://stackoverflow.com/questions/42285441/how-to-read-in-csv-with-d3-v4) – ksav Sep 27 '18 at 10:42

2 Answers2

0

Since d3 v5 deprecated request(), you can use d3.text() to parse the CSV in a customizable way, which is what this exercise in the book is trying to do.

The relevant changes I made to this example, then, were,

d3.text("vehicle_sales_data.csv")
  .then(function(response) {
  ...
    var rows = d3.csvParseRows(response);
Radio-
  • 3,151
  • 21
  • 22
-1

d3.csv("https://gist.githubusercontent.com/d3noob/fa0f16e271cb191ae85f/raw/bf896176236341f56a55b36c8fc40e32c73051ad/treedata.csv", function(data) {
  console.log(data);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min.js"></script>
ksav
  • 20,015
  • 6
  • 46
  • 66
  • It doesn't work. It shows an error. 'Uncaught (in promise) TypeError: Cannot read property 'length' of undefined at Object.parseRows [as csvParseRows] (d3.js:5753) at' – Orne Novino Sep 26 '18 at 19:31
  • It think your error might be related to a part of code that you have not shared here. – ksav Sep 27 '18 at 10:45
  • The full code its available here: https://github.com/alignedleft/d3-book/blob/master/chapter_16/01_initial_chart.html In the line 188 there is an error in de color, it's already fixed. – Orne Novino Sep 27 '18 at 14:22
  • Do you want to edit your question to include the error and the code that you believe is causing the error? – ksav Sep 27 '18 at 18:52
  • In my opinion the error is in the part that I posted. If it's in another line, sincerely I can't detect where it really is. – Orne Novino Sep 27 '18 at 19:01