Understanding D3 domain and ranges

前端 未结 1 1614
别那么骄傲
别那么骄傲 2021-01-07 22:45

I have a temperature range of 33 degrees to 64 degrees F. I\'m trying to figure out the pixel position of 59 degrees along a y-axis that spans 600 pixels. This is for a colu

相关标签:
1条回答
  • 2021-01-07 23:00

    The domain is the complete set of values, so in this case that is all of your temperatures, from 33 to 64. The range is the set of resulting values of a function, in this case the resulting values of scaling your temperatures from 0 to 600.

    So you're almost there, you're just using the wrong range - in this case your range should be the span of your y-axis (0 - 600):

    var scale = d3.scale.linear().domain([33, 64]).range([0, 600]);

    Which will result in scale(59) giving an output of 503.2258064516129.

    0 讨论(0)
提交回复
热议问题