D3.js - 无法读取未定义的属性“轴” [英] D3.js - Cannot read property 'axis' of undefined

查看:127
本文介绍了D3.js - 无法读取未定义的属性“轴”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码段:

var xScale = d3.scaleLinear().range([MARGINS.left, WIDTH -  MARGINS.right]).domain([scaleMin, scaleMax]);
var yScale = d3.scaleLinear().range([HEIGHT - MARGINS.top, MARGINS.bottom]).domain([minValue,maxValue+numberOfSignals*300]);
xAxis = d3.svg.axis().scale(xScale);
yAxis = d3.svg.axis().scale(yScale).orient("left");

vis.append("svg:g")
        .attr("transform", "translate(0," + (HEIGHT - MARGINS.bottom) + ")")
        .call(xAxis);

vis.append("svg:g")
        .attr("transform", "translate(" + (MARGINS.left) + ",0)")
        .call(yAxis);

这是我的代码。但每次我运行它我得到错误情节:91未捕获的TypeError:无法读取未定义的属性'轴'。
事情就是以前它起作用了。有更新吗?
谢谢!

this is my code. But everytime i run it i get the error "plot:91 Uncaught TypeError: Cannot read property 'axis' of undefined". The thing is that it worked before. was there an update? Thanks!

推荐答案

对于版本4
它必须是:

For version 4 It has to be:

var xScale = d3.scaleLinear().range([MARGINS.left, WIDTH - MARGINS.right]).domain([scaleMin, scaleMax]);

var yScale = d3.scaleLinear().range([HEIGHT - MARGINS.top, MARGINS.bottom]).domain([minValue,maxValue+numberOfSignals*300]);


var xAxis = d3.axisBottom()
    .scale(xScale);

var yAxis = d3.axisLeft()
    .scale(yScale);

而不是下面的代码(将在版本3中使用):

Instead of this code below(will work in version 3):

xAxis = d3.svg.axis().scale(xScale);
yAxis = d3.svg.axis().scale(yScale).orient("left");

这篇关于D3.js - 无法读取未定义的属性“轴”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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