[英]Customized chart using d3 in react native
我按照Mark所链接的块中提到的方法进行操作。
这是我创建的示例的链接。
首先,更改线条的笔触样式
.line {
fill: none;
stroke: url(#temperature-gradient); // change here
stroke-width: 1.5px;
}
然后添加temperature-gradient
svg:
svg.append("linearGradient")
.attr("id", "temperature-gradient")
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", 0).attr("y1", y(0)) // 0 as the min index
.attr("x2", 0).attr("y2", y(500)) // 500 as the max index
.selectAll("stop")
.data([
{offset: "0%", color: "red"}, // red for low index
{offset: "30%", color: "gray"}, // index 150 for grey color
{offset: "100%", color: "stealblue"} // to steal blue for index above 150
])
.enter().append("stop")
.attr("offset", function(d) { return d.offset; })
.attr("stop-color", function(d) { return d.color; });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.