d3 append simple area

你。 提交于 2019-12-13 09:26:24

问题


I want to append simple area to my chart with end points of area values as constants.

percentArea = d3.svg.area()
      .interpolate('linear')
      .x0(0)
      .x1(w)
      .y0(h/4)
      .y1(h);

I want to append this area directly and give it a color fill. Thanks for help. I am having specially hard time trying to get the area fill. The chart shows a line over the area but no fill when I tried.

Edit: Trying to make the question more clear and specific : The issue I face is only when I try to call my function without passing data. The area fill works as expected when I call percentArea(data). However I am unable to understand why I must pass data when endpoints of my area are constant.


回答1:


You need to ensure that the path you have rendered is being filled. There are two ways you can do this:

Set a Style

path.style("fill", "steelblue");

Set a class and leverage CSS

path.attr("class", "filled-area");

// In CSS
.filled-area {
    fill: steelblue;
}

Here's a quick example:

Area Chart with a Stroke:

Area Chart with no fill

As you can see this defaults to black

Area Chart with correct fill



来源:https://stackoverflow.com/questions/32554055/d3-append-simple-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!