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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is it possible to make the legend draggable by the user ?

Thread ID:





132308 Aug 25,2017 09:28 AM UTC Aug 29,2017 03:41 AM UTC WPF 3
Tags: SfChart
Asked On August 25, 2017 09:28 AM UTC


I'd like to let the user click on the legend of an SfChart and be able to drag it wherever he wants on the screen?
Is it possible to implement it ?
In all your examples I've always seen a static legend position.
Thank you,

Silvio Scattaglia

Durgadevi Selvaraj [Syncfusion]
Replied On August 28, 2017 12:27 PM UTC

Thanks for contacting Syncfusion Support. 
We have analyzed your requirement and currently we don’t have legend dragging support in SfChart. However, We have achieved your requirement in workaround by setting DockPosition as Floating to the legend and corresponding chart area position as Legend offsets using mouse events of chart as shown in the below code, 
    <chart:SfChart  MouseMove="SfChart_MouseMove"  MouseLeftButtonUp="SfChart_MouseLeftButtonUP"> 
            <chart:NumericalAxis /> 
            <chart:NumericalAxis /> 
               <chart:ChartLegend x:Name="legend" DockPosition="Floating" MouseLeftButtonDown="legend_MouseLeftButtonDown"  OffsetX="200" CheckBoxVisibility="Visible"/> 
          <chart:LineSeries ItemsSource="{Binding Collection}"  Label="Line Series" XBindingPath="XValue" YBindingPath="YValue"/> 
private void SfChart_MouseMove(object sender, MouseEventArgs e) 
            var chart = sender as SfChart; 
            if (isDragable) 
                var _offsetX = e.GetPosition(chart).X; 
                var _offsetY = e.GetPosition(chart).Y; 
                (chart.Legend as ChartLegend).OffsetX = _offsetX -50; 
                (chart.Legend as ChartLegend).OffsetY = _offsetY; 
            if ((chart.Legend as ChartLegend).IsMouseOver) 
                if (Mouse.OverrideCursor == null) 
                    Mouse.OverrideCursor = Cursors.Hand; 
   private void SfChart_MouseLeftButtonUP(object sender, MouseButtonEventArgs e) 
            isDragable = false; 
   private void legend_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
            isDragable = true; 
Please find the output screenshot, 
We have prepared a demo sample based on your requirement and it can be downloaded from the below link, 
Please let us know if you have any concerns. 
Durgadevi S 

Replied On August 28, 2017 04:00 PM UTC

Thank you for your help!

Durgadevi Selvaraj [Syncfusion]
Replied On August 29, 2017 03:41 AM UTC

Hi Silvio, 
Thanks for your response. 
Please let us know if you required any further assistance on this. 
Durgadevi S 


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

or the page will be automatically redirected to 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