Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: .. is not a function in javascript

I am trying to use d3.js to draw line chart.

Javascript

function lineChart(){
    ...
}

function update(){
    ...
    var lineChart = lineChart()
        .x(d3.scale.linear().domain([2011, 2014]))
        .y(d3.scale.linear().domain([0, 1000000]));
    ...
}

But the console says that Uncaught TypeError: lineChart is not a function.
How to fix this?

like image 585
Miron Avatar asked Dec 06 '22 18:12

Miron


1 Answers

You are shadowing your function.

This happens when you declare another variable/function with the same name of an upper one. What you should do is to give another name to the second one declaration just like @andlrc says in his comment.

var lineChartResult = lineChart()...

You can learn more about shadowing in here: Setting & Shadowing Properties

like image 183
David Gomez Avatar answered Dec 25 '22 16:12

David Gomez