Create gradient line fill based on value python

How do I create a graph that changes the line gradient to red the higher it goes & lower is green?
i’ve tried so many things and I am very stumped, please help ty

You can use the getGradientFillHelper function to generate the appropriate canvas gradient. There’s an example in the gallery: