This is a migrated thread and some comments may be shown as answers.

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

1 Answer 120 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oleg
Top achievements
Rank 1
Oleg asked on 19 Nov 2014, 05:19 PM
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?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 21 Nov 2014, 08:49 AM
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.

Regards,
Adrian
Telerik
 

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.

 
Tags
Chart
Asked by
Oleg
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Share this question
or