RadChartView: Legend

In this article, you will learn to use the built-in legend in RadChartView for Android.


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:

    barSeries1.CombineMode = ChartSeriesCombineMode.Stack;
    barSeries2.CombineMode = ChartSeriesCombineMode.Stack;

    barSeries1.LegendTitle = "first";
    barSeries2.LegendTitle = "second";

    RadLegendView legendView = new RadLegendView (this);
    legendView.LegendProvider = chartView;

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(460,100);
    legendView.LayoutParameters = layoutParams;

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.Orientation = Android.Widget.Orientation.Vertical;


    ViewGroup rootView = (ViewGroup)FindViewById(Resource.Id.container);

Here's the result:



The default behaviour of the RadLegendView is to show the legend items vertically. However you can change the orientation of the items to horizontal with:

   legendView.LegendOrientation = LinearLayout.HORIZONTAL;

The posible values for the orientation are:

  • LienarLayout.HORIZONTAL
  • LienarLayout.VERTICAL


By default the scroll of the legend items is disabled. In order to enable the horizontal and vertical scroll you can use:

   legendView.CanScrollHorizontally = true;
   legendView.CanScrollVertically = true;

Finally, 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:

    PieSeries series = new PieSeries();
    // This assumes that the data models have a property with
    // the signature public string Name { get; }.
    series.NameBinding = new PropertyNameDataPointBinding("Name");