Candlestick up/downcolor

2 posts, 0 answers
  1. Jason
    Jason avatar
    1 posts
    Member since:
    Jul 2012

    Posted 23 Dec 2015 Link to this post

    I am trying to figure out how to set the upcolor and downcolor of a candlestick chart. I am not finding these properties on the series. Please advise. Thank you.
  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 24 Dec 2015 Link to this post

    Hi Jason,

    Thank you for writing.

    By default only the points which are falling have fill and you can set it's color like this:
    candlestickSeries.BorderColor = Color.Red;

    If you want to have specific colors for all points you should create a cutom renderer. The following snippet shows how you can implement this for the candlestic series:
    public class CustomCartesianRenderer : CartesianRenderer
    {
        public CustomCartesianRenderer(CartesianArea area)
            : base(area)
        { }
     
        protected override void Initialize()
        {
            base.Initialize();
     
            for (int i = 0; i < this.DrawParts.Count; i++)
            {
                CandlestickSeriesDrawPart linePart = this.DrawParts[i] as CandlestickSeriesDrawPart;
                if (linePart != null)
                {
                    this.DrawParts[i] = new CustomCandlestickSeriesDrawPart((CandlestickSeries)this.Area.Series[0], this);
                }
            }
        }
    }
    public class CustomCandlestickSeriesDrawPart : CandlestickSeriesDrawPart
    {
        public CustomCandlestickSeriesDrawPart(CandlestickSeries series, IChartRenderer renderer)
        : base(series, renderer)
    { }
        public override void DrawSeriesParts()
        {
           // base.DrawSeriesParts();
            RadGdiGraphics radGraphics = new RadGdiGraphics(((Graphics)this.Renderer.Surface));
     
            for (int i = 0; i < this.Element.Children.Count; i++)
            {
                DataPointElement childElement = (DataPointElement)this.Element.Children[i];
     
                RadRect slot = this.Element.DataPoints[i].LayoutSlot;
                RectangleF rect = new RectangleF((float)(this.OffsetX + slot.X), (float)(this.OffsetY + slot.Y), (float)slot.Width, (float)slot.Height);
                rect.Y++;
                OhlcDataPoint point = this.Element.DataPoints[i] as OhlcDataPoint;
                GraphicsPath path = ConstructPath(point, rect);
     
                if (childElement.BackgroundShape != null)
                {
                    childElement.BackgroundShape.Paint((Graphics)radGraphics.UnderlayGraphics, rect);
                }
     
                 
                if (point.IsFalling)
                {
                    childElement.BackColor = Color.Green;
                    FillPrimitiveImpl fill = new FillPrimitiveImpl(childElement, null);
                    fill.PaintFill(radGraphics, path, rect);
                }
                else
                {
                    childElement.BackColor = Color.Red;
                    FillPrimitiveImpl fill = new FillPrimitiveImpl(childElement, null);
                    fill.PaintFill(radGraphics, path, rect);
                }
     
                BorderPrimitiveImpl border = new BorderPrimitiveImpl(childElement, null);
                border.PaintBorder(radGraphics, null, path, rect);
            }
        }
    }

    I hope this helps. Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top