Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3.js - Cannot read property 'axis' of undefined

Here is my code snippet:

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);

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!

like image 747
cmplx96 Avatar asked Jul 26 '16 07:07

cmplx96


1 Answers

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); 

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

xAxis = d3.svg.axis().scale(xScale); yAxis = d3.svg.axis().scale(yScale).orient("left"); 
like image 104
Cyril Cherian Avatar answered Sep 30 '22 09:09

Cyril Cherian