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. Image for the cookie policy date

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


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

3 Replies

DS Durgadevi Selvaraj Syncfusion Team 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 

SI Silvio August 28, 2017 04:00 PM UTC

Thank you for your help!

DS Durgadevi Selvaraj Syncfusion Team 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 

Live Chat Icon For mobile
Up arrow icon