javascript - How to solve TypeError: d3.time is undefined? -


i want parse data/time using d3.js. purpose created 1 javascript file , use var d3 = require('d3'). install d3 using npm install d3, , tried npm install d3 --save saves in package.json file :

{   "name": "school",   "version": "1.0.0",   "description": "",   "main": "index.js",   "scripts": {     "test": "echo \"error: no test specified\" && exit 1"   },   "author": "",   "license": "isc",   "dependencies": {     "browserify": "^13.1.0",     "bufferutil": "^1.2.1",     "d3": "^4.2.2",     "express": "^4.14.0",     "guid": "0.0.12",     "gulp": "^3.9.1",     "react": "^15.3.1",     "react-dom": "^15.3.1",     "reactify": "^1.1.1",     "utf-8-validate": "^1.2.1",     "vinyl-source-stream": "^1.1.0",     "websocket": "^1.0.23",     "ws": "^1.1.1"   } } 

however, i'm facing exception:

typeerror: d3.time undefined 

program code:

'use strict';  var d3 = require("d3"); var latency_arr = []; var time_arr = []; var timeformat = d3.time.format('%h:%m:%s %l');  module.exports = {   histogram: function(data) {     console.log(data);     return {        getbin: function() {          var jsonobject = json.parse(data);         this.time_arr = jsonobject.time;         for(var = 0 ; < this.time_arr.length ; i++){             temp_time = this.time_arr[i];             this.time_arr[i] = new date(timeformat.parse(temp_time));         }         return this.time_arr;       },        addvalue: function(date, value) {         return true;       },        getvalues: function() {         if(data !== undefined){             var jsonobject = json.parse(data);             this.latency_arr = jsonobject.latency;             return this.latency_arr;         }       }     };   } }; 

checking :

> var d3 = require('d3'); undefined 

but d3 module in node_modules directory.

why didn't recognize d3 module? missing?

you requiring d3 v4.2.2 doesn't have d3.time property more, part of d3 v3. according changelog time formats have been subject general namespace flattening , therefore renamed follows:

that said, recognize d3 object, wheras d3.time undefined. changing code

var timeformat = d3.timeformat('%h:%m:%s %l'); 

should trick.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -