Articles in this section
Category / Section

How to redraw WPF Chart (SfChart) while dragging the series out of the range?

1 min read

This document demonstrates how to redraw in a predefined range for the WPF Chart (SfChart) using the DragEnd event. This event allows you to implement functions after dragging a segment in the chart. By utilizing this event, you can obtain the new position and axis value where the segment is dragged and subsequently adjust the secondary axis values of the Minimum and Maximum properties based on the new value. 


XAML

<chart:SfChart>
    <chart:SfChart.PrimaryAxis>
         <chart:CategoryAxis x:Name="axis1"/>
    </chart:SfChart.PrimaryAxis>
    <chart:SfChart.SecondaryAxis>
         <chart:NumericalAxis x:Name="sec_axis" 
Minimum="10" Maximum="350"
RangePadding="Round"
Interval="50"/>     </chart:SfChart.SecondaryAxis>     <chart:LineSeries XBindingPath="Product"
YBindingPath="Price"
DragEnd="LineSeries_DragEnd"
ItemsSource="{Binding Products}"
EnableDragTooltip="True"
EnableSegmentDragging="True">     </chart:LineSeries> </chart:SfChart>

C#

private void LineSeries_DragEnd(object sender, Syncfusion.UI.Xaml.Charts.ChartDragEndEventArgs e)
{
   if(e.NewYValue<sec_axis.Minimum)
   {
     sec_axis.Minimum = e.NewYValue;
   }
   else if(e.NewYValue>sec_axis.Maximum)
   {
     sec_axis.Maximum = e.NewYValue;
   }
}

Output:

The initial segment position and its position while being dragged are displayed in the first image.

LIne series before dragging in WPF Chart

The second image shows the segment redrawn after dragging.

Line series after dragging in WPF Chart


Conclusion

I hope you enjoyed learning how to redraw WPF Chart while dragging the series out of the range.

You can refer to our WPF Chart feature tour page know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Chart Examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied