简体   繁体   English

y在d3条形图上缩放

[英]y scale on d3 bar chart

I am trying to build a stacked bar chart in d3. 我正在尝试在d3中构建堆积条形图。

Here's my jsfiddle: http://jsfiddle.net/maneesha/gwjkgruk/4/ 这是我的jsfiddle: http//jsfiddle.net/maneesha/gwjkgruk/4/

I'm trying to fix it so that the y-axis starts at zero. 我正在尝试修复它,以便y轴从零开始。

I thought this is where that was set up and this is how it should be: 我认为这是设置的地方,它应该是这样的:

yScale = d3.scale.linear()
    .domain([0, yMax])
    .range([0, height]),

but it doesn't work. 但它不起作用。 Changing domain to this gets the scale right but messes up all my rects. 将域名更改为此权限会使权限缩小,但会影响我的所有权限。

yScale = d3.scale.linear()
    .domain([yMax, 0])
    .range([0, height]),

What am I doing wrong? 我究竟做错了什么?

Try to modify your scale like that: 尝试修改你的比例:

yScale = d3.scale.linear()
  .domain([0,yMax])
  .range([height,0]),

and then when you fill the rect: 当你填写矩形时:

.attr('y', function (d) {
    return height - yScale(d.y0);
 })
.attr('height', function (d) {
    return height - yScale(d.y);
 })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM