ChartView for Xamarin.Android: Legend
In this article, you will learn to use the built-in legend in RadChartView for Android.
Overview
You can start from the BarSeries example and add a second instance of the BarSeries with stack combine mode. Then you need to set their legend title and create a new instance of RadLegendView. RadLegendView needs a legend provider which will provide the data. You can use RadCartesianChartView as a LegendProvider:
Here's the result:
The legend for the pie chart is a little bit different. The pie series does not have a legend title because each point in the series means something different, the title is taken from the data points with a name binding. For example:
Orientation
The default behavior of the RadLegendView is to show the legend items vertically. However you can change the orientation of the items to horizontal with LegendOrientation property:
The possible values for the orientation are:
- OrientationHelper.Horizontal
- OrientationHelper.Vertical
Scrolling
By default the scroll of the legend items is disabled. In order to enable the horizontal and vertical scroll you can use:
Selection
RadLegendView supports selection by setting the AllowSelection property to true.
The LegendItemSelected event can be used to determine the selected LegendItem
.