Miron Miron - 1 year ago 72
Javascript Question

Uncaught TypeError: .. is not a function in javascript

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


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?


You are shadowing you 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