3

I'm sure the solution is straight forward, but I'm trying to find out how to limit the range of radius when I plot circles onto a geomap. I have values that range in size significantly, and the larger values end up covering a significant amount of the map.

d3.csv("getdata.php", function(parsedRows) {

    data = parsedRows
    for (i = 0; i < data.length; i++) {
      var mapCoords = this.xy([data[i].long, data[i].lat])
      data[i].lat = mapCoords[0]
      data[i].long = mapCoords[1]
    }

    vis.selectAll("circle")
    .data(data)
    .enter().append("svg:circle")
    .attr("cx", function(d) { return d.lat })
    .attr("cy", function(d) { return d.long })
    .attr("stroke-width", "none")
    .attr("fill", function() { return "rgb(255,148,0)" })
    .attr("fill-opacity", .4)
    .attr("r", function(d) { return Math.sqrt(d.count)})
  })

This is what I have right now.

4

1 回答 1

2

您可能希望scales通过设置domain(最小/最大输入值)和range(最小/最大输出允许值)来使用 d3。为简化此操作,请毫不犹豫地使用d3.mind3.max设置域的值。

d3.scale将返回一个函数,您可以在分配r属性值时使用该函数。例如:

var scale = d3.scale.linear.domain([ inputMin, inputMax ]).range([ outputMin, outputMax ]);
vis.selectAll("circle")
  // etc...
  .attr( 'r', function(d) { return scale(d.count) });
于 2013-02-28T04:13:00.973 回答