javascript - .onmousedown executing on page load -


i'm trying have different graph shown when click on different polygon. function executes when page loads, though defined .onmousedown. function

function iscrtaj(data, arg) {     alert(arg);     var barwidth = 13;     var w = 700;     var h = (barwidth + 10) * data.length;      var xscale = d3.scale.linear()         .domain([0, d3.max(data, function (d) {             return d.bodovi;         })])         .rangeround([0, 280]);      var yscale = d3.scale.linear()         .domain([-1, data.length])         .range([0, h]);      var bargraph = d3.select("body")         .append("svg")         .attr("width", w)         .attr("height", h);      svg.selectall("rect")         .data(data)         .enter()         .append("rect")         .attr("x", 870)         .attr("y", function (d, i) {             return yscale(i);         })         .attr("height", barwidth)         .attr("width", width).transition().duration(1000)         .attr("width", function (d) {             return xscale(d.bodovi);         })         .attr("fill", "blue");      svg.selectall("text")         .data(data)         .enter()         .append("text")         .attr("x", function (d) {             return xscale(d.bodovi) + 910;         })         .attr("y", function (d, i) {             return yscale(i);         })         .attr("dx", barwidth / 2)         .attr("dy", "0.8em")         .attr("text-anchor", "end")         .attr("style", "font-weight: bold; font-size: 11; font-family: helvetica, sans-serif")         .text(function (d) {             return d.bodovi + " %";         })         .style("fill", "black");      svg.selectall("text.xaxis")         .data(data)         .enter()         .append("text")         .attr("x", 830)         .attr("y", function (d, i) {             return yscale(i) + barwidth - 2;         })         .attr("dx", -barwidth / 2)         .attr("text-anchor", "end")         .attr("style", "font-size: 12; font-family: helvetica, sans-serif")         .text(function (d) {             return d.stranka;         })         .attr("transform", "translate(20, 0)")         .attr("class", "xaxis")         .attr("fill", "black"); } 

and rest of code on jsfiddle. (the pop-up here make sure function taking right arguments.) http://jsfiddle.net/y27ng/

.on("mousedown",iscrtaj(data1, 5)) 

calls function instantly , result/return if function bound event

.on("mousedown",function(){iscrtaj(data1, 5);}) 

using anonymous function might fix problem, scope , lifetime of data can have impact on this.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -