将梯度颜色设置为绘图(JS)中的线图
如何将线路设置为梯度颜色?我想成为最小值红色和最大值绿色,并且之间的所有内容都应该是渐变。
这是我用于设置数据的代码:
// setting the data for the graph
this.graph.data = [{
type: 'scatter',
mode: 'lines',
y: Array.from(this.dataForGraph.values()),
x: Array.from(this.dataForGraph.keys()),
}];
这是图形相关代码:
public graph: any = {
layout: {
width: this.eRef?.nativeElement.clientWidth,
height: 400,
plot_bgcolor: 'white',
margin: {
l: 60,
r: 30,
b: 30,
t: 80,
},
xaxis: {
type: 'date',
},
yaxis: {
title: { text: "Load [MW]" },
autorange: true,
}
},
data: [
],
};
How can I set the line to gradient color? I would like to be the minimum value red and the maximum value green, and everything in between should be gradient.
This is my code for setting the data:
// setting the data for the graph
this.graph.data = [{
type: 'scatter',
mode: 'lines',
y: Array.from(this.dataForGraph.values()),
x: Array.from(this.dataForGraph.keys()),
}];
This is the graph related code:
public graph: any = {
layout: {
width: this.eRef?.nativeElement.clientWidth,
height: 400,
plot_bgcolor: 'white',
margin: {
l: 60,
r: 30,
b: 30,
t: 80,
},
xaxis: {
type: 'date',
},
yaxis: {
title: { text: "Load [MW]" },
autorange: true,
}
},
data: [
],
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论