将梯度颜色设置为绘图(JS)中的线图

发布于 2025-01-30 10:57:09 字数 750 浏览 4 评论 0原文

如何将线路设置为梯度颜色?我想成为最小值红色和最大值绿色,并且之间的所有内容都应该是渐变。

这是我用于设置数据的代码:

// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文