Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Gradient colors and implicit color conversion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Gradient colors and implicit color conversion

    I have two questions on colors
    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

    Code:
            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);
            }
    ​


    #2
    Hello giogio1,

    Thank you for your post.

    You may find the post below helpful, it discusses gradient brushes.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    127 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    73 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    115 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    109 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    88 views
    0 likes
    Last Post CarlTrading  
    Working...
    X