简体   繁体   English

设置SVG元素的宽度和高度-d3.js

[英]set width and height of an SVG element - d3.js

I am using d3 to build up a graph. 我正在使用d3建立图表。

Now, i am trying to set width and height of that area ike this - 现在,我正在尝试为此设置该区域的宽度和高度-

   var area2 = d3.svg.area()
            .interpolate("monotone")
            .attr("width", this.options.width)
            .attr("height", 100);

But, i get this error -- 但是,我得到这个错误-

Uncaught TypeError: undefined is not a function 未捕获的TypeError:undefined不是函数

See here - 看这里 - 在此处输入图片说明

NOTE: I have tested and this.options.width is not null - It's value is 1727. 注意:我已经测试过,并且this.options.width不为this.options.width其值为1727。

I am new to d3 and SVG, any suggestion will help. 我是d3和SVG的新手,任何建议都会有所帮助。

svg.area provides x, y0, and y1 (as was previously stated by In Code). svg.area提供x,y0和y1(如In Code先前所述)。 y0 to y1 is bottom to the top - bottom of graph (x axis) to the line if it is a line graph. y0到y1是线的底部(从图的顶部到底部-x线的底部)。

Something like this sounds like what you want: 听起来像您想要的东西:

  var area2 = d3.svg.area()
        .x(function(d) { return x(d.X_VARIABLE); })
        .y0(height)
        .y1(function(d) { return y(d.Y_VARIABLE); });

Great example: http://www.d3noob.org/2013/01/filling-area-under-graph.html 很好的例子: http//www.d3noob.org/2013/01/filling-area-under-graph.html

As noted by the author, you should be defining your domains for x and y as well (if you have not). 正如作者所指出的,您还应该为x和y定义域(如果没有)。

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

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