javascript - Indexing into array with functions -



javascript - Indexing into array with functions -

i'm trying modify illustration of kernel density estimation https://github.com/jasondavies/science.js/tree/master/examples/kde have 1 1 line instead of 2. need modify code below. more specifically, need modify .data(d3.values(science.stats.bandwidth)). chrome developer tools can see variable returned var bw = d3.values(science.stats.bandwidth) following:

bw: array[2] 0: function (x) { 1: function (x) { length: 2 __proto__: array[0]

i've tried indexing variable, returned function cannot used plotting. becomes undefined.

var granularity = 0.1; var x_min = 30; var x_max = 110; d3.json("faithful.json", function(faithful) { info = faithful; var w = 800, h = 400, x = d3.scale.linear().domain([30, 110]).range([0, w]); bins = d3.layout.histogram().frequency(false).bins(x.ticks(60))(data), max = d3.max(bins, function(d) { homecoming d.y; }), y = d3.scale.linear().domain([0, .1]).range([0, h]), kde = science.stats.kde().sample(data); var vis = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); var bars = vis.selectall("g.bar") .data(bins) .enter().append("g") .attr("class", "bar") .attr("transform", function(d, i) { homecoming "translate(" + x(d.x) + "," + (h - y(d.y)) + ")"; }); bars.append("rect") .attr("fill", "steelblue") .attr("width", function(d) { homecoming x(d.dx + 30) - 1; }) .attr("height", function(d) { homecoming y(d.y); }); var line = d3.svg.line() .x(function(d) { homecoming x(d[0]); }) .y(function(d) { homecoming h - y(d[1]); }); var bw = d3.values(science.stats.bandwidth); vis.selectall("path") /* .data(d3.values(science.stats.bandwidth)) */ .data(bw[1]) .enter().append("path") .attr("d", function(h) { homecoming line(kde.bandwidth(h)(d3.range(x_min, x_max, granularity))); }); });

.data() expects array. use:

.data([bw[1]])

example here.

javascript d3.js

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -