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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    64 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    93 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    48 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    106 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    63 views
    0 likes
    Last Post PaulMohn  
    Working...
    X