Skip to main content

How to: Create a Movable Legend at Runtime

This example shows how to provide the capability for end-users to move a chart's legend at runtime.

For this, you need to assign a TranslateTransform object (named legendTransform) to the Legend.RenderTransform property. This allows you to control and modify a legend position.

Before changing a legend position, you should handle the ChartControl.MouseLeftButtonDown and ChartControl.MouseLeftButtonUp events to make sure that a legend has been dragged by a mouse. After that, it becomes possible to calculate a distance by which a legendTransform object should be moved. To accomplish this task, handle the ChartControl.MouseMove event.