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