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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X