gpt4 book ai didi

javascript - 如何在图表线上方添加渐变颜色?

转载 作者:行者123 更新时间:2023-11-29 14:43:28 24 4
gpt4 key购买 nike

Here我通过反转 y 轴在图表区域的顶部获得渐变颜色。检查下图。

   yAxis: {
reversed: true,
showFirstLabel: false,
showLastLabel: true
}

enter image description here

我不想反转 y 轴,如果我反转 y 轴,我的图表也会反转。我想要在不使用此反向 Y 轴的情况下位于图表线顶部的渐变颜色。如果 highcharts 中有任何其他选项,请建议我。

谁能帮我解决这个问题。

enter image description here

我正在处理实时随机数据。在这种情况下,只有数据经过的区域应该获得渐变色,聊天中数据以外的空白区域不应获得渐变色。

根据@DaMaxContent 的回答,输出将如下图所示。

enter image description here

我不想要填充图表数据其他区域的渐变。你能帮我解决这个问题吗?

最佳答案

分解:

您可以使用 gridZindex 和 backgroundColor/fillColor 属性来产生所需的效果。唯一的问题是网格必须显示在图表上

解决方案:

DEMO

背后的代码:

chart: {
type: 'area',
backgroundColor: { //<<--that is what you are using as fill color
linearGradient : {
x1: 0,
y1: 1,
x2: 0,
y2: 0
},
stops : [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
}
},

rangeSelector: {
selected: 1
},

title: {
text: 'AAPL Stock Price'
},

yAxis: {
reversed: false,
showFirstLabel: false,
showLastLabel: true,
gridZIndex: 1000 //<<--grid Z index is used to display grid lines over the graph instead of under it
},

series: [{
name: 'AAPL Stock Price',
data: data,
threshold: null,
fillColor : "#fff", //<<--fill color under the line to simulate effect
zIndex: 1000,
tooltip: {
valueDecimals: 2
}
}]

如果你想去掉边缘颜色区域,你可以用 chart: { [... ,] margin: 0 [, ...] 去掉图形边距然后使用容器的填充作为图形边距。

更多信息:

*范围选择器区​​域不会受到影响

关于javascript - 如何在图表线上方添加渐变颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35503946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com