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 : Nov 16th 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:

Created:

Updated:

Platform:

Replies:

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

Hi,

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, 
MainWindow.xaml: 
 
    <chart:SfChart  MouseMove="SfChart_MouseMove"  MouseLeftButtonUp="SfChart_MouseLeftButtonUP"> 
             
        <chart:SfChart.PrimaryAxis> 
            <chart:NumericalAxis /> 
        </chart:SfChart.PrimaryAxis> 
 
        <chart:SfChart.SecondaryAxis> 
            <chart:NumericalAxis /> 
        </chart:SfChart.SecondaryAxis> 
 
            <chart:SfChart.Legend> 
               <chart:ChartLegend x:Name="legend" DockPosition="Floating" MouseLeftButtonDown="legend_MouseLeftButtonDown"  OffsetX="200" CheckBoxVisibility="Visible"/> 
            </chart:SfChart.Legend> 
 
          <chart:LineSeries ItemsSource="{Binding Collection}"  Label="Line Series" XBindingPath="XValue" YBindingPath="YValue"/> 
            
        </chart:SfChart> 
 
 
MainWindow.cs: 
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. 
 
Regards,  
Durgadevi S 




Silvio
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. 
 
Regards,   
Durgadevi S 


CONFIRMATION

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.

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

;