Add horizontal line on chart click

Hello,

I'd like to add a horizontal line on a chart click. Line should be drawn on pointed Y value. I have checked the documentation and available events and could't find the answer how to do that. Please help with that.


Regards.

Paul



1 Reply 1 reply marked as answer

GV Gopalakrishnan Veeraraghavan Syncfusion Team September 19, 2023 02:06 PM UTC

Hi Pawel,


We have analyzed your query and recommend using the ChartStripline to render a horizontal line when the chart is clicked. You can achieve this by utilizing the OnCrosshairMove event to obtain the Y value of the crosshair and the ChartMouseClick event to set the Y value to start values of the ChartStripline. For your reference, we have attached a sample link and GIF Image. Please check the following code snippet.



<ChartEvents ChartMouseClick="OnMouseEvent" OnCrosshairMove="CrosshairMove"></ChartEvents>

 

<ChartPrimaryYAxis>

     @if (Start != 0)

     {

         <ChartStriplines>

             <ChartStripline Start="@Start" Size="1" SizeType="SizeType.Pixel" Color="red" />

         </ChartStriplines>

     }

     <ChartAxisCrosshairTooltip Enable="true"></ChartAxisCrosshairTooltip>

</ChartPrimaryYAxis>

 

public void CrosshairMove(CrosshairMoveEventArgs args)

{

     CurrentStartValue = (double)args.AxisInfo[0].Value;

}

 

public void OnMouseEvent(ChartMouseEventArgs args)

{

     Start = CurrentStartValue;

     StateHasChanged();

}


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AddHorizontalStripline1655642278.zip


GIF Image:

HorizontalLine.gif




Kindly revert us if you have any concerns.



Regards,

Gopalakrishnan Veeraraghavan


Marked as answer
Loader.
Up arrow icon