I'm using Syncfusion's ColumnSeries. I want to use it to display the ColumnBar even when the data value is 0. Is it possible?

I'm using Syncfusion's ColumnSeries. I want to use it to display the ColumnBar even when the data value is 0. Is it possible?

like this one. attached below


Attachment: Capture_da165c03.zip

2 Replies 1 reply marked as answer

YP Yuvaraj Palanisamy Syncfusion Team September 15, 2021 03:08 AM UTC

Hi Denis, 
  
Greetings from Syncfusion.  
  
We have analyzed your query and attached screenshot, we are trying to achieve your requirement “Coloumn series rendered at Value 0 with corner radius” by workaround. And we will update the comple details on or before 16th September 2021. We appreciate your patience until then. 
 
Regards, 
Yuvaraj. 


Marked as answer

YP Yuvaraj Palanisamy Syncfusion Team September 16, 2021 01:53 PM UTC

 
Thanks for your patience.

 
We have achieved your requirement “Render column series when yValue is 0” by workaround with the help of CustomRenderer support in Xamarin.Forms. Please find the code example below. 
 
CodeSnippet: 
<chart:SfChart.Series>                
    <local:ColumnSeriesExt x:Name="series1"  
                           ItemsSource="{Binding Data}"  
                           XBindingPath="XValue" 
                           YBindingPath="YValue"  
                           CornerRadius="20" 
                           Color="DarkCyan" 
                           CustomColor="Cyan"> 
    </local:ColumnSeriesExt> 
</chart:SfChart.Series> 
 
CustomRenderer.cs [Android project] 
public class CustomChartRenderer : SfChartRenderer 
    { 
        protected override void OnElementChanged(ElementChangedEventArgs<SfChart> e) 
        { 
            base.OnElementChanged(e); 
        } 
 
        public override SfChartExt CreateNativeChart() 
        { 
            return new CustomChart(Android.App.Application.Context); 
        } 
    } 
 
public class CustomChart : SfChartExt 
    { 
        public CustomChart(Android.Content.Context context) : base(context) 
        { 
 
        } 
 
        protected override Native.ChartSeries CreateNativeChartSeries(ChartSeries formSeries) 
        { 
            if (formSeries is ColumnSeriesExt) 
            { 
                return new CustomColumnSeries() { CustomColor = (formSeries as ColumnSeriesExt).CustomColor}; 
            } 
 
            return base.CreateNativeChartSeries(formSeries); 
        } 
    } 
 
public class CustomColumnSeries : Native.ColumnSeries 
    { 
        public Xamarin.Forms.Color CustomColor { get; set; } 
        protected override Native.ChartSegment CreateSegment() 
        { 
            return new CustomColumnSegment(); 
        } 
    } 
 
public class CustomColumnSegment : Native.ColumnSegment 
    { 
        Paint paint = new Paint(); 
         
        public override void OnDraw(Canvas canvas) 
        { 
            if (Top == Bottom) 
            { 
                if (!float.IsNaN(Left) && !float.IsNaN(Top) && !float.IsNaN(Right) && !float.IsNaN(Bottom)) 
                {                      
                    if (paint.Handle == IntPtr.Zero) 
                    { 
                        paint = new Paint(); 
                    } 
 
                    paint.Color = SfChartRenderer.GetWindowsColor((this.Series as CustomColumnSeries).CustomColor); 
                    paint.SetStyle(Paint.Style.Fill); 
                    paint.StrokeWidth = StrokeWidth; 
                    canvas.Save(); 
 
                    var halfWidth= (Right - Left) / 2; 
                    canvas.DrawCircle(Left + halfWidth, Bottom - halfWidth, halfWidth, paint); 
                    canvas.Restore(); 
                } 
            } 
            else 
            { 
                base.OnDraw(canvas); 
            } 
        } 
    } 
 
Also, we have attached the complete sample for your reference. Please find the sampel from the below link. 
 
  
Output: 
 
 
Please let us know if you have any concern. 
 
Regards, 
Yuvaraj. 


Loader.
Up arrow icon