Chart's legend isn't scrollable and gets a huge size when many elements on a chart

Thread is closed for posting
2 posts, 0 answers
  1. Oleg
    Oleg avatar
    8 posts
    Member since:
    Nov 2014

    Posted 19 Nov 2014 Link to this post

    I created a pie chart:

    TKChart *c = [[TKChart alloc] initWithFrame:self.view.bounds];

        NSMutableArray *ar = [NSMutableArray new];
        for (int i = 0; i < 20; i++) {
            TKChartDataPoint *p = [[TKChartDataPoint alloc] initWithValue:@(1) name:[NSString stringWithFormat:@"Point %d",i]];
            [ar addObject:p];
        TKChartPieSeries *series = [[TKChartPieSeries alloc] initWithItems:ar];
        [c addSeries:series];
        c.legend.hidden = NO;

        [self.view addSubview:c];
        TKChartLegendContainer *cont = c.legend.container;
    //    cont.stack.stretchMode = TKLayoutStretchModeVertical;
        cont.stack.alignmentMode = TKLayoutAlignmentModeHorizontalCenter;
        cont.stack.orientation = TKStackLayoutOrientationHorizontal;
        cont.stack.stretchMode = TKLayoutStretchModeHorizontal;

    Doesn't matter what I do to the legend configuration, I can't make the legend's container resize or move to an appropriate position.

    I want the legend to be scrollable (It inherits from UIScrollView) and I want it to be centred above the pie chart. How can this be achieved?

  2. Adrian
    Adrian avatar
    174 posts

    Posted 21 Nov 2014 Link to this post

    Hello Avner,

    Thank you for writing.

    The easiest way to achieve the described scenario is to create new legend instance and then add it to the view hierarchy. This way you can easily configure the position and size of the legend view. The following code snippet shows how to create a legend that is centred above a pie series:
    TKChartLegendView *legendView = [[TKChartLegendView alloc] initWithChart:_chart];
    legendView.frame = CGRectMake( _chart.bounds.size.width / 2 - 40, 20, 80, 100);
    legendView.container.stack.alignmentMode = TKLayoutAlignmentModeRight;
    [self.view addSubview:legendView];
    [legendView reloadItems];

    Currently TKChartLegendView does not support scrolling. However this is a feature that we are planning to implement in a future version. It is already logged in our feedback portal. Feel free to vote/comment.

    I hope this helps. We will be glad to help in case you have further questions.


    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.

Back to Top