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
chartSeries1.ConfigItems.FinancialItem.PriceDownColor = Color.Orange;
chartSeries1.ConfigItems.FinancialItem.PriceUpColor = Color.Yellow;
|
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
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);
}
}
} |