We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Candle Series with different Colours and how to access a chart segment on rendered.

So basically I want to have a candle series with different colours at different parts of the x-axis .. I couldn't find any easy way to do this, so tried just adding three separate series to start with. Unfortunately there is a bug where if there is more than one series the bars are not drawn properly and really thin, but that aside, I tried to adapt another solution I found on here by using a custom class

    public class CustomCandleSeries1 : CandleSeries
    {
        //Returns the Candle Segments
        public ObservableCollection<ChartSegment> CustomSegment
        {
            get
            {
                return this.Segments;
            }
        }
    }

I can now access the Segments and change colour like this;

    void ColorSegment( ChartSegment segment)
        {
                var canvas = segment.GetRenderedVisual() as Canvas;

                if (canvas is null) return; // before ready

                    (canvas.Children[0] as Rectangle).Fill = 
              
     etc.
}

The problem i have is when to do this. The example I followed handled the Chart Loaded and Size Changed events but that was for doing something different and although it works ok, it doesnt handle new data being added to the Series Data

I have tried accessing the Collection Changed Event for the Segments Collection in the Chart Series to catch new items added and call my function at that point - this doesnt work though as at the point the Event is fired the Candle is not rendered, so  segment.GetRenderedVisual() is null.

So my question is, is there any way of injecting my function when a new Candle is created and rendered?

Hope that makes sense and thanks for any help.




3 Replies

MK Muneesh Kumar G Syncfusion Team June 28, 2019 12:35 PM UTC

Hi Tom, 
 
Greetings from Syncfusion.  
 
We have analyzed your requirement and you can achieve this overriding CreateSegments method in inherited CandleSeries class and able to set required color for segment as per the below code snippet. 
 
Code snippet 
  public class CustomCandleSeries : CandleSeries 
    { 
 
        public override void CreateSegments() 
        { 
            base.CreateSegments(); 
 
            foreach (var segment in Segments) 
            { 
                var canvas = segment.GetRenderedVisual() as Canvas; 
 
                if (canvas is null) return; // before ready 
 
                (canvas.Children[0] as Rectangle).Fill = new SolidColorBrush(Colors.AliceBlue); 
            } 
        } 
    } 
 
 
  <local:CustomCandleSeries  ItemsSource="{Binding StockPriceDetails}"  
                                XBindingPath="Date"  High="High" Open="Open"    
                                Close="Close" Low="Low"   
                                Label="Candleseries" ShowTooltip="True"  
                                chart:ChartTooltip.EnableAnimation="True"/> 
 
 
Please let us know if you have any other queries.  
 
Regards, 
Muneesh Kumar G.   



TO Tom July 3, 2019 11:07 AM UTC

Thank you, this works great. Is there a similar thing I could do - in terms of over-riding a function - to change the colour of gridlines dependent on the axis value?
thanks


MK Muneesh Kumar G Syncfusion Team July 3, 2019 12:31 PM UTC

Hi Tom, 
 
Thanks for your update, we have analyzed your requirement and we would like to inform you that we don’t have support to customize each gridline with different color.  
 
Regards, 
Muneesh Kumar G.    


Loader.
Live Chat Icon For mobile
Up arrow icon