javascript - is it possible to tweak the d3 bubble chart to obtain the bubbles at scattered positions instead of a circle pack? -
i need implement d3 bubble chart,but bubbles scattered out in division ( spread across division @ specific coordinates ) instead of circle pack layout.is possible set positions of bubbles in such way using d3.js?
sure, don't use layout , set each circles cx
, cy
yourself:
svg.selectall('circle') .data(data) .enter() .append('circle') .attr('r', function(d){ return d.r; }) .attr('cx', function(d){ return d.x; }) .attr('cy', function(d){ return d.y; });
example here.
edits
you can arrange bubbles anyway want, positioning them in x/y 2d space. if wanted complex, using d3's scales map user space pixel space.
here's sine wave example:
var svg = d3.select('body') .append('svg') .attr('width', 500) .attr('height', 500); var xscale = d3.scale.linear() .domain([0, 10]) .range([0, 500]); var yscale = d3.scale.linear() .domain([-1, 1]) .range([0, 500]); var data = []; (var = 0; < 10; i+=0.1){ data.push({ x: i, y: math.sin(i), r: math.random() * 10 }); } svg.selectall('circle') .data(data) .enter() .append('circle') .attr('r', function(d){ return d.r; }) .attr('cx', function(d){ return xscale(d.x); }) .attr('cy', function(d){ return yscale(d.y); });
another example here.
Comments
Post a Comment