How to float the legend on chart?
Description:
Legends are not restricted to be positioned on the top of the chart. It can be placed on or around the plot area. This article describes how the legends position can be customized.
Solution:
Essential chart for Xamarin.Forms provides the following properties to align or position the legends anywhere in the chart.
The DockPosition property is used to position the legends at the bottom, left, right, or top of the chart, and the Floating property is used to position the legends anywhere over the plot area using the coordinates.
The OffsetX and OffsetY properties are used to provide horizontal and vertical offsets for the legends. These properties work only when the DockPosition is set to Floating.
The following code illustrates how to use this property.
XAML
<chart:SfChart.Legend> <chart:ChartLegend OffsetX="50" OffsetY="45" DockPosition="Floating" /> </chart:SfChart.Legend>
C#
chart.Legend = new ChartLegend() { OffsetX = 50, OffsetY = 45, DockPosition = LegendPlacement.Floating };