[英]Multiple Plots with Different Y Scales Using D3
I am making multiple line plots using d3 (see functional example http://jsfiddle.net/hSrP7/ ). 我正在使用d3绘制多个线图(请参见功能示例http://jsfiddle.net/hSrP7/ )。 However, I would like to have different yscales for each plot. 但是,我希望每个图都有不同的yscale。 I've tried a syntax such as the following, but without success: 我尝试了如下语法,但没有成功:
var diseases = ['Maternal_Mortality', 'Child_Mortality', 'Malaria']
var min = []
min['Maternal_Mortality'] = .4
min['Child_Mortality'] = .3
min['Malaria'] = .1
var max = []
max['Maternal_Mortality'] = .7
max['Child_Mortality'] = .6
max['Malaria'] = .8
yscale = function(dis) {
yval = d3.scale.linear().domain([min[dis], max[dis]).range([plotHeight -
bottomPadding, topPadding])
return yval
}
var yaxes = d3.svg.axis()
.scale(diseases.forEach(function(d) {return yscale(d)}))
Here is the link to the fiddle using this syntax that doesn't work(http://jsfiddle.net/Hn5JX/). 这是使用不起作用的语法的小提琴的链接(http://jsfiddle.net/Hn5JX/)。 Is there a way to pass different yscales to each graph? 有没有办法将不同的yscale传递给每个图形? The graphs that I'm actually working with have much larger differences. 我实际使用的图形之间的差异更大。 Thanks, 谢谢,
You just had a type-o in your javascript. 您刚刚在JavaScript中输入了O。 You had forgotten to close the array passed into yscale's domain: 您忘记了关闭传递到yscale的域中的数组:
.domain([min[dis], max[dis]) // change to:
.domain([min[dis], max[dis]])
http://jsfiddle.net/Hn5JX/2/ http://jsfiddle.net/Hn5JX/2/
Fixed the fiddle and it's rendering but I'll edit the answer if you're still not seeing what you need. 修复了小提琴及其渲染,但是如果您仍然没有看到所需的内容,我将编辑答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.