My requirement id to draw a chart as just shown below in react native.
In my research I found d3 is the best suitable tool to create graphs.
Dataset was added like below and its working perfectly with react native.
Any idea how can I make the data set colored as shown below (when it comes to different regions the color changed).
I followed the approach mentioned in the block linked by Mark.
Here is a link to an example I created.
You start by changing the stroke style for the line
.line {
fill: none;
stroke: url(#temperature-gradient); // change here
stroke-width: 1.5px;
}
Then add the 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; });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.