TKChart has built-in support for legends – descriptions about the charts on the plot. The items displayed in the legend are series specific i.e. for the pie chart the data points are shown in the legend, whereas for line series only one item is shown for each series.
If you would like to show the legend in
TKChart, you should set its hidden property to NO. The default value is YES. The legend supports showing a series title.
chart.Legend.Hidden = false;
You can alter the position and offset origin of legend by setting its position:
chart.Legend.Style.Position = TKChartLegendPosition.Right;
The legend can be anchored to concrete side by using the following values
It can float by using
TKChartLegendPositionFloat value. In this case, you can offset its origin manually by setting its
chart.Legend.Style.Position = TKChartLegendPosition.Floating; chart.Legend.Style.OffsetOrigin = TKChartLegendOffsetOrigin.TopLeft; chart.Legend.Style.Offset = new UIOffset(10, 10);
You can alter visibility of the legend's title by changing
chart.Legend.TitleLabel.Text = "Companies"; chart.Legend.ShowTitle = true;
In addition, you can disable the series selection via legend by setting
allowSelection property to NO.
The legend can be customized by using its style object. It contains the following properties:
position- Determines where the legend should be placed.
offset- Determines the offset at which to place the legend, according to the specified offsetOrigin.
offsetOrigin- Determines the starting point for the offset property.
fill- Gets or sets the fill color to be used as a background.
stroke- Gets or sets stroke color to be used for the legend frame.
You can use the legend outside the chart view. You should create an instance of
TKChartLegendView and add it as subview to desired view.
var legendView = new TKChartLegendView (chart); legendView.Frame = new CGRect (20, 20, 320, 100); this.View.AddSubview(legendView); legendView.ReloadItems ();