Chcę przeanalizować dane/czas za pomocą D3.js. W tym celu utworzyłem jeden plik javascript i używam var d3 = require('d3')
. zainstalować używając npm install d3
D3, a także próbował npm install d3 --save
który zapisuje je w pliku package.json
:Jak rozwiązać TypeError: d3.time jest niezdefiniowana?
{
"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"
}
}
Jednak jestem skierowaną ten wyjątek:
TypeError: d3.time is undefined
kod programu:
'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 i = 0 ; i < 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;
}
}
};
}
};
Sprawdzanie:
> var d3 = require('d3');
undefined
Ale moduł d3 znajduje się w katalogu node_mulules.
Dlaczego nie rozpoznał modułu d3? czego mi brakuje?
@ altocumulus- ok dostał. Jak mogę użyć ** d3.time.scale() ** i ** d3.scale.linear() **? – kit
To wszystko w linku changelog w odpowiedzi. d3.time.scale -> d3.scaleTime i d3.scale.linear -> d3.scaleLinear – odedfos