0

Murray (2017) suggests the following code for loading a csv file and parsing columns usign D3.js V4. This code no longer works in V5. How can it be restructured in order to work? Thanks

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>D3: Line chart</title>
    <script type="text/javascript" src="/../../d3.js"></script>
    <style type="text/css">

    </style>
</head>
<body>
    <script type="text/javascript">

        var dataset; 
        //Function for converting CSV values from strings to Dates and numbers
        var rowConverter = function(d) {
            return {
                date: new Date(+d.year, (+d.month - 1)),  //Make a new Date object for each year + month
                average: parseFloat(d.average)  //Convert from string to float
            };
        }

        //Load in data
        d3.csv("mauna_loa_co2_monthly_averages.csv", rowConverter, function(data) {

            var dataset = data;

            //Print data to console as table, for verification
            console.table(dataset, ["date", "average"]);
}

1 Answer 1

4

For v5, d3-fetch is your friend as d3-request has been deprecated.

For instance:

d3.csv("/path/to/file.csv", rowConverter).then(function(data){ do whatever })

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.