D3 tickFormat错误,说明n.getMonth不是函数 [英] D3 tickFormat error stating n.getMonth is not a function

查看:358
本文介绍了D3 tickFormat错误,说明n.getMonth不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用D3创建一些数据的线图。我以毫秒为单位给它一个日期,我想用小时和分钟显示它。我试过将它作为新日期(myDate)的返回值传递给它,这也不起作用。



以下是我在运行时遇到的错误。 Uncaught TypeError:n.getMonth不是函数

我也尝试通过运行新日期(时间)来转换所有ms时间,但没有任何改变。

这是我的图形代码。可变时间是指基于ms的时间测量数组。

 函数processData(allText){
var allTextLines = allText.split(/ \r \ n | \\ \
/);
var headers = allTextLines [0] .split(',');
var lines = [];
for(var i = 1,arrayLen = allTextLines.length; i< arrayLen; i ++){
var data = allTextLines [i] .split(',');
if(data.length === headers.length){
lines.push({time:Date.parse(data [0]),last:data [1]});


var final = []
var d3Formater = d3.time.format(%m /%d /%Y);
for(var i = lines.length-1,base =(lines [lines.length-1] .time - 14400001); i> 0; i--){
if(lines [i ] .time> base){

var temp = new Date(lines [i] .time)
console.log(temp);
final.push(d3Formater.parse(temp));
}
}
删除行;
var xMin = new Date(d3.min(time));
var xMax = new Date(d3.max(time));

var vis = d3.select(#visualization),
WIDTH = 1000,
HEIGHT = 500,
MARGINS = {
top: 20,
正确:20,
底部:20,
剩下:50
},
xScale = d3.scale.linear()。range([MARGINS。 ([xMin,xMax]),
yScale = d3.scale.linear()。range([HEIGHT - MARGINS.top,MARGINS.bottom])。domain( [yMin,yMax]),

xAxis = d3.svg.axis()
.scale(xScale)
.tickFormat(d3.time.format(%m- %d)),

yAxis = d3.svg.axis()
.scale(yScale);

预先感谢您。

解决方案

尝试更改此行:

  xScale = d3.scale.linear()... 。

尝试使用...

  xScale = d3.time.scale().... 


I am using D3 to create a line graph of some data. I am passing it a date in ms and I want to display it in hours and minutes. I have tried passing it the value as a return of new Date(myDate), which also doesn't work.

Here is the error I am getting when I run. "Uncaught TypeError: n.getMonth is not a function"

I have also tried to convert all the ms time based by running them through new Date(time), but nothing changed.

Here's my graph code. variable time refers to an array of ms based time measurements.

    function processData(allText) {
    var allTextLines = allText.split(/\r\n|\n/);
    var headers = allTextLines[0].split(',');
var lines = [];
for(var i =1, arrayLen = allTextLines.length; i<arrayLen; i++) {
    var data = allTextLines[i].split(',');
    if (data.length === headers.length) {
        lines.push({time: Date.parse(data[0]), last: data[1]});
    }
}
var final = []
var d3Formater = d3.time.format("%m/%d/%Y");
for(var i = lines.length-1, base = (lines[lines.length-1].time - 14400001); i>0; i--) {
    if(lines[i].time>base) {

        var temp = new Date(lines[i].time)
        console.log(temp);
        final.push(d3Formater.parse(temp));
    }
}
delete lines;
var xMin = new Date(d3.min(time));
var xMax = new Date(d3.max(time));

var vis = d3.select("#visualization"),
    WIDTH = 1000,
    HEIGHT = 500,
    MARGINS = {
       top: 20,
        right: 20,
        bottom: 20,
        left: 50
    },
    xScale = d3.scale.linear().range([MARGINS.left, WIDTH - MARGINS.right]).domain([xMin, xMax]),
    yScale = d3.scale.linear().range([HEIGHT - MARGINS.top, MARGINS.bottom]).domain([yMin, yMax]),

        xAxis = d3.svg.axis()
            .scale(xScale)
            .tickFormat(d3.time.format("%m-%d")),

        yAxis = d3.svg.axis()
            .scale(yScale);

Thank you in advance.

解决方案

Try changing this line:

xScale = d3.scale.linear()....

Try using...

xScale = d3.time.scale()....

这篇关于D3 tickFormat错误,说明n.getMonth不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆