Customise legend's item's appearance not working

2 posts, 0 answers
  1. Oleg
    Oleg avatar
    8 posts
    Member since:
    Nov 2014

    Posted 20 Nov 2014 Link to this post

    I am also trying to customise the legend's appearance. Not working :(
    I want to make the legend items much bigger and change the shape of the indicator icon:

    TKChartLegendContainer *legendContainerScrollView = chart.legend.container;
        legendContainerScrollView.stack.itemSpacing = 50;
        TKChartLegendItem *item = [legendContainerScrollView itemAtIndex:0]; = CGSizeMake(50, 50); // Not working

    Not working...

    I also want to change the shape of the legend's indicator to square:

    I see in the debugger that :

    TKChartLegendItem *item = [legendContainerScrollView itemAtIndex:0];TKChartLegendItem *item = [legendContainerScrollView itemAtIndex:0];
    // item.icon is a TKChartShapeView - would like to change the shape to "Square"

    Also I see that TKChartLegendItem.h declares a protocol "TKChartLegendItemDelegate"

    But no way to become the delegate without sub classing TKChartSeries:

     @discussion The legend asks all series first about the count of legend items they will provide and then gets this count of items.

    But I don't see any implementation or declaration in TKSeries of this protocol.

    It also seems like a lot of work for something very trivial

    Here is the appearance I want to achieve in the attached file:

  2. Jack
    Jack avatar
    2335 posts

    Posted 21 Nov 2014 Link to this post


    You can change the legend item shape by using a custom UIView for the legend icon. Here is a sample code for this (assuming that you are using a pie chart):
    for (int i = 0; i<_pieChart.legend.container.itemCount; i++) {
        TKChartLegendItem *item = [_pieChart.legend.container itemAtIndex:i];
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
        TKChartPaletteItem *paletteItem = [_pieChart paletteItemForSeries:_pieChart.series[0] atIndex:i];
        TKSolidFill *fill = (TKSolidFill*)paletteItem.fill;
        view.backgroundColor = fill.color;
        item.icon = view;

    However, currently it is not possible to achieve the same layout like in the attached file. We know about this limitation and we are working on improving how legends can be customized in TKChart.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft R3 2016 release webinar banner
Back to Top