admin管理员组文章数量:1307007
The following is an Area Range chart which has a gradient.
/
What I want to do is have the gradient follow the curve, so that the color at any point along the bottom line is the same, and it ends at the same color when it reaches the top line. I am pretty sure that this is not currently an option in highcharts, but I just wanted to see if anyone has run into this before. Here is the code that currently generates the gradient:
series: [{
name: "Shade",
fillColor: {
linearGradient: [0, 0, 0, 300],
stops: [
[0, "#4572A7"],
[1, "rgba(2,0,0,0)"]
]
},
data: [
[0, 14733, 18890],
[1, 16583, 21642],
//... rest here
[10, 42417, 61955]
]
}]
Thanks
Note: this is not the same as Gradient Fill on Line Chart (Highcharts) since I need the gradient to follow the curve
The following is an Area Range chart which has a gradient.
http://jsfiddle/gXpHH/1/
What I want to do is have the gradient follow the curve, so that the color at any point along the bottom line is the same, and it ends at the same color when it reaches the top line. I am pretty sure that this is not currently an option in highcharts, but I just wanted to see if anyone has run into this before. Here is the code that currently generates the gradient:
series: [{
name: "Shade",
fillColor: {
linearGradient: [0, 0, 0, 300],
stops: [
[0, "#4572A7"],
[1, "rgba(2,0,0,0)"]
]
},
data: [
[0, 14733, 18890],
[1, 16583, 21642],
//... rest here
[10, 42417, 61955]
]
}]
Thanks
Note: this is not the same as Gradient Fill on Line Chart (Highcharts) since I need the gradient to follow the curve
Share Improve this question edited May 23, 2017 at 12:33 CommunityBot 11 silver badge asked Feb 8, 2013 at 20:56 Justin BicknellJustin Bicknell 4,80820 silver badges27 bronze badges 1- how can we use three colors as gradient lets say (Green, Yellow, and Red) ? – Shihabudheen K M Commented Apr 8, 2020 at 7:08
2 Answers
Reset to default 6 +50The difficulty is the granularity: Highcharts draws one single SVG path for the series' points, and associates that one path with the gradient. If your series data is relatively linear however, the following approximation might be useful. See the jsfiddle that I've created:
Assuming that your series data is not static, my demo includes two series and a function that, for each series, attempts to dynamically create the linearGradient that es closest to your requirement:
function getLinearGradient(series) {
var lastY0=null, lastY1=null, maxY0=null, maxY1=null;
$.each(series.data, function(key,value) {
maxY0 = Math.max(value[1],maxY0);
maxY1 = Math.max(value[2],maxY1);
lastY0 = value[1];
lastY1 = value[2];
});
var firstY0 = series.data[0][2],
firstY1 = series.data[0][2]
;
var minY0=maxY0, minY1=maxY1;
$.each(series.data, function(key,value) {
minY0 = Math.min(value[1],minY0);
minY1 = Math.min(value[2],minY1);
});
var minY = minY0,
maxY = maxY1,
heightY = maxY - minY
;
var gradient = {
x1: 10 + ( ((firstY0-minY) / heightY) * 80 ) + "%",
y1: "10%",
x2: 10 + ( ((lastY1-minY) / heightY) * 80 ) + "%",
y2: "90%"
};
return gradient;
};
Of course, this approach is not a full-blown solution and only useful if you're dealing with data that approximately follows a linear curve. Here's the jsfiddle
I don't have any example, nor do I know for sure if it is already in the specifications, but I am pretty sure the only way to acplish this effect would be using svg mash gradients.
You could use the path points as boundary points for the mash matrix and get the effect you want.
See here for further information.
本文标签: javascriptHighchart Area Range chart with gradient that follows the lineStack Overflow
版权声明:本文标题:javascript - Highchart Area Range chart with gradient that follows the line - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741829522a2399849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论