Candle Color

Hi,


I am trying to color candles in a candle series chart on winform using c# based on external conditions. I tried below approaches after going through the forum.. but none is working. Please let me know how can I color individual candles based on a condition.


Approach 1 :

==========

ChartSeries Candle_Series = new ChartSeries("CandleStick", ChartSeriesType.Candle);

for (int i = 0; i < display_Bar_Count; i++)

{

Candle_Series.Points.Add(Candles_To_Display[i].StartTime.ToString("dd"),

(double)Candles_To_Display[i].Open,

(double)Candles_To_Display[i].High,

(double)Candles_To_Display[i].Low,

(double)Candles_To_Display[i].Close);

Candle_Series.Styles[i].Interior = new BrushInfo(Color.Orange);

}

Approach 2:

===========

Candle_Series.PrepareStyle += Candle_Series_PrepareStyle;


private void Candle_Series_PrepareStyle(object sender, ChartPrepareStyleInfoEventArgs args)

{

ChartSeries candleSeries = sender as ChartSeries;

if (candleSeries.Points[args.Index].YValues[2] > candleSeries.Points[args.Index].YValues[3])

{

args.Style.Interior = new BrushInfo(Color.SteelBlue);

}

else

{

args.Style.Interior = new BrushInfo(Color.Brown);

}


}


Thanks,

Amit


3 Replies

YP Yuvaraj Palanisamy Syncfusion Team July 21, 2021 12:57 PM UTC

Hi Amitabha, 
 
Greetings from Syncfusion. 
 
We would like to let you know that the candle series color can be customized by using the PriceDownColor and PriceUpColor properties as per the below code snippet.  
   
Code Snippet:  
   
   
chartSeries1.ConfigItems.FinancialItem.PriceDownColor = Color.Orange; 
chartSeries1.ConfigItems.FinancialItem.PriceUpColor = Color.Yellow; 
   
   
Also, we have prepared the sample for your reference. Please find the sample from the below link.  
   
   
Output:  
 
 
Regards, 
Yuvaraj. 



AM Amitabha July 22, 2021 05:27 AM UTC

Hi Yuvaraj ,


Thanks for your response. I tried as you mentioned here and candle colors are appearing. But my requirement is to paint candles for more than two conditoins (say 5 colors are defined for 5 different conditions and whenever a particular condition satisfies, the color of that candle will be the one set for that particular condition). With PriceUpColor  And PriceDownColor, I am limited to painting my Candles for only 2 conditions [Whether price closed above Or below]. How can I paint the candles for any number of user defined condition ?


Thanks,

Amit



YP Yuvaraj Palanisamy Syncfusion Team July 23, 2021 10:07 AM UTC

Hi Amitabha, 
 
We would like to inform that the Style.Interior property to change the appearance of the Candle color when PriceDownColor and PriceUpColor property to Color.Empty. Please find the code example below. 
 
CodeSnippet: 
 
chartSeries1.ConfigItems.FinancialItem.PriceDownColor = Color.Empty; 
chartSeries1.ConfigItems.FinancialItem.PriceUpColor = Color.Empty; 
 
chartSeries1.PrepareStyle += Form1_PrepareStyle; 
 
private void Form1_PrepareStyle(object sender, ChartPrepareStyleInfoEventArgs args) 
{ 
    ChartSeries series = sender as ChartSeries; 
    if (series != null && args.Index < series.Points.Count) 
    { 
        if (series.Points[args.Index].YValues[2] < 10) 
        { 
             args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Blue); 
        } 
        else if (series.Points[args.Index].YValues[2] <= 12) 
        { 
            args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Red); 
        } 
        else if (series.Points[args.Index].YValues[2] <= 15) 
        { 
            args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Green); 
        } 
        else 
        { 
            args.Style.Interior = new Syncfusion.Drawing.BrushInfo(Color.Yellow); 
        } 
    } 
} 
 
Also, we have attached sample for your reference. Please find the sample from the below link. 
 
 
Output: 
 
 
Regards, 
Yuvaraj. 


Loader.
Up arrow icon