Candlestick up/downcolor

3 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
    2907 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. willie johnson
    willie johnson avatar
    7 posts
    Member since:
    Apr 2006

    Posted 27 Feb 2018 in reply to Dimitar Link to this post

    thank you, Dimitar, please see my other post i was able to display them using SmartLabels, just need to figure out how to add connecting lines, please see attachment "snip_20180226163707.png", i want to add connecting line that connects the label to the candlestick with the ball on the end connecting to a single candlestick like in that pics, do i use the code u sent me to do that, also how do keep the label connected to candlestick when user uses mouse scroll, and pan?

     

    See my post: https://www.telerik.com/forums/custom-smartlabel-scroll-pan-issue-help-format-smartlabel

     

Back to Top