了解D3域和范围 [英] Understanding D3 domain and ranges

查看:45
本文介绍了了解D3域和范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的温度范围是33华氏度到64华氏度.我试图找出沿600像素的y轴59度的像素位置.这是一个柱形图.

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 column chart.

完全公开,这是我已经努力了一段时间的作业,只是还没有弄清楚.

Full disclosure, this is homework that I've been grappling for a while and simply have not yet figured it out.

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

scale(59)返回53.677419354838705,这是错误的答案.600-53.677419354838705也是错误的答案.

scale(59) returns 53.677419354838705 which is the wrong answer. 600 - 53.677419354838705 is also the wrong answer.

我可能会缺少什么?

谢谢.

推荐答案

是一组完整的值,因此在这种情况下,这是您的所有温度,从33到64.范围是函数的结果值集,在这种情况下,是将温度从0缩放到600的结果值.

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.

所以您快到了,您所使用的范围是错误的-在这种情况下,您的范围应该是y轴的跨度(0-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]);

这将导致 scale(59)给出 503.2258064516129 的输出.

这篇关于了解D3域和范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆