Help Line SfCartesianChart

Hallo,

is it possible to draw a straight helpline over the Chart on a specific y-axis value, the line needs only be horizontal?

Thanks,

Markus 


1 Reply

DR Dhanaraj Rajendran Syncfusion Team November 24, 2023 12:50 PM UTC

Hi Markus,


We have  achieved the requirement by extending the necessary series, adding a BindableProperty to obtain the specific y-axis value, and drawing the horizontal line at the required y-value by overriding the DrawSeries() method. We have updated the code snippet and attached a demo for reference.


 internal class SeriesExt : ColumnSeries

 {

     public static readonly BindableProperty SpecificYValueProperty = BindableProperty.Create(nameof(SpecificYValue), typeof(double), typeof(SeriesExt),0.0,BindingMode.Default);

 

     public double SpecificYValue

     {

         get { return (double)GetValue(SpecificYValueProperty); }

         set { SetValue(SpecificYValueProperty, value); }

     }

   

     protected override void DrawSeries(ICanvas canvas, ReadOnlyObservableCollection<ChartSegment> segments, RectF clipRect)

     {

         base.DrawSeries(canvas, segments, clipRect);

         if (ActualXAxis != null && ActualYAxis != null)

         {

             float startPoint = (float)clipRect.Left;

             float endPoint = (float)clipRect.Right;

 

  <----Here the specific Y value was converted to screenPoint---->

             var yPoint = ActualYAxis.ValueToPoint(SpecificYValue);

 

             DrawLine(canvas, startPoint, yPoint, endPoint, yPoint);

         }

     }

 

     private void DrawLine(ICanvas canvas, float startPoint, float yPoint1, float endPoint, float yPoint2)

     {

         canvas.StrokeColor = Colors.Black;

         canvas.StrokeSize = 5;

         canvas.DrawLine(startPoint, yPoint1, endPoint, yPoint2);

     }

 }


 <chart:SfCartesianChart>

   

 

     <model:SeriesExt ItemsSource="{Binding Data}" XBindingPath="Month" YBindingPath="High" Label="Temperatue Variation" Fill="#18c1f5" SpecificYValue="16"/>

   

 </chart:SfCartesianChart>


Screenshot 2023-11-24 162350.png


If you have any concerns regarding this response, feel free to ask.

Regards,

Dhanaraj Rajendran.


Attachment: HorizontalHelpline_ab013cd1.zip

Loader.
Up arrow icon