Set gradient color to line chart in plotly (js)

Viewed 132

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: [

    ],
    
  };
0 Answers
Related