I had a code in Ninjatrader7 that allowed me to convert a number into a color gradient which I could simply apply to a plot
What is a simple way to color a plot with a gradient color that goes for example from red to blue as a function of a number that goes from 0 to 1 ? I just need the lead.
Also I used to have this code below but the last line (return Color.FromRgb(red, green, blue)
, produces the error
Cannot implicitly convert type 'System.Windows.Media.Color' to 'System.Windows.Media.SolidColorBrush'
what's the correct way to convert it?
Thank you.
G
private System.Windows.Media.SolidColorBrush GetGradientColor(System.Windows.Media.SolidColorBrush startColor, System.Windows.Media.SolidColorBrush endColor, double razio)
{
double raz = Math.Max(0.0, Math.Min(1.0, razio));
byte red = Convert.ToInt32((1.0 - raz) * (double)startColor.R + raz * (double)endColor.R);
byte green = Convert.ToInt32((1.0 - raz) * (double)startColor.G + raz * (double)endColor.G);
byte blue = Convert.ToInt32((1.0 - raz) * (double)startColor.B + raz * (double)endColor.B);
return Color.FromRgb(red, green, blue);
}

Comment