Chart: Legend

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.

Configure legend

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 = NO;
chart.legend.isHidden = false
chart.Legend.Hidden = false;

You can alter the position and offset origin of legend by setting its position: = TKChartLegendPositionRight; = TKChartLegendPosition.right
chart.Legend.Style.Position = TKChartLegendPosition.Right;

The legend can be anchored to concrete side by using the following values TKChartLegendPositionLeft, TKChartLegendPositionRight, TKChartLegendPositionTop and TKChartLegendPositionBottom.

It can float by using TKChartLegendPositionFloat value. In this case, you can offset its origin manually by setting its offset and offsetOrigin properties: = TKChartLegendPositionFloating; = TKChartLegendOffsetOriginTopLeft; = UIOffsetMake(10, 10); = TKChartLegendPosition.floating = TKChartLegendOffsetOrigin.topLeft = UIOffsetMake(10, 10)
chart.Legend.Style.Position = TKChartLegendPosition.Floating;
chart.Legend.Style.OffsetOrigin = TKChartLegendOffsetOrigin.TopLeft;
chart.Legend.Style.Offset = new UIOffset(10, 10);

Customize legend

You can alter visibility of the legend's title by changing showTitle property.

chart.legend.titleLabel.text = @"Companies";
chart.legend.showTitle = YES;
chart.legend.titleLabel.text = "Companies"
chart.legend.showTitle = true
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:

Embeding legend outside TKChart

You can use the legend outside the chart view. You should create an instance of TKChartLegendView and add it as subview to desired view.

TKChartLegendView *legendView = [[TKChartLegendView alloc] initWithChart:chart];
legendView.frame = CGRectMake(20, 20, 320, 100);
[self.view addSubview:legendView];
[legendView reloadItems];
let legendView = TKChartLegendView(chart: chart)
legendView.frame = CGRect(x: 20, y: 20, width: 320, height: 100)
var legendView = new TKChartLegendView (chart);
legendView.Frame = new CGRect (20, 20, 320, 100);
legendView.ReloadItems ();