Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
Converting Rebinding Exports d3.js v3 to v5 VarName.on not a function

I am trying to convert a data manager API from "Develop a D3.js Edge" - original code https://github.com/backstopmedia/D3Edge/blob/master/code/Chapter07/script.js - from in d3v3 to d3v5.

I have addressed the d3.rebind (I think, I used the advice from d3.rebind in D3 v4).

My issue and question is that I am having issues with other areas of the code - namely how to use Promises (or asyn/await) here. I think this is the source of my error:

Uncaught (in promise) TypeError: loadCsv.on is not a function at Object.exports.loadCsvData (d3Edge_RUPro_Chapter7_v5.3.html:73:21) at d3Edge_RUPro_Chapter7_v5.3.html:136:27

but I am uncertain, any advice would be great.

This js.fiddle is how far I have got: https://jsfiddle.net/Maltbyjim/xqmau08d/4/

I tried this attempt to use promises:

   //Create a method to load the csv file, and apply cleaning function asynchronously.
        exports.loadCsvData = function(_file, _cleaningFunc) {

            //Create the csv request using d3.csv.
            //**how you load csv cahnges in d3v5
            // https://stackoverflow.com/questions/49599691/how-to-load-data-from-a-csv-file-in-d3-v5

            // **previous...
            //const loadCsv = d3.csv(_file);
            loadCsv = d3.csv(_file).then(function(_data){
                return _data
            }); //<---SOURCE OF THE ERROR
            
            
            //On the progress event, dispatch the custom dataLoading event.
            //**previous...
            //loadCsv.on('progress', function() { dispatch.dataLoading(d3.event.loaded);});
            processCsv = loadCsv.then( function (value){
                return Promise.all(
                    value().on('progress', function() { dispatch.dataLoading(d3.event.loaded);}),
                    value.get(function (_err, _response) {
                        //Apply the cleaning function supplied in the _cleaningFunc parameter.
                        _response.forEach(function (d) {
                            _cleaningFunc(d);
                    });
                })
            );
            //Assign the cleaned response to our data variable.
            data = _response;

            //Dispatch our custom dataReady event passing in the cleaned data.
            dispatch.dataReady(_response);
            });
        };
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!