Miron Miron - 2 years ago 149
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download