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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

145565 Jun 28,2019 07:00 AM UTC Jul 3,2019 12:31 PM UTC WPF 3
loading
Tags: SfChart
Tom
Asked On June 28, 2019 07:00 AM UTC

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.




Muneesh Kumar G [Syncfusion]
Replied On 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.   


Tom
Replied On 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

Muneesh Kumar G [Syncfusion]
Replied On 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.    


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon