Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
330
How to implement IGLegend to IGChart?
posted

I am using IGChart in one of my IOS projects and couldn't find how to display legend view on it. I have checked the infragistics SDK but the given 2 lines of code snippet regarding how to use legend with IGChart is not clear. So if you could add an example about legend usage with IGChart I will be pleased. Also here is what I am doing with Objective C:

@property (strong, nonatomic) IGLegend *chartLegend;

Firstly, I am initialising the legend within a function.

self.chartLegend = [[IGLegend alloc] initWithLegendType:IGChartLegendTypeSeries];
[self.chartLegend setFrame:CGRectMake(10, 10, 200, 100)];
self.chartLegend.translatesAutoresizingMaskIntoConstraints = NO;
self.chartLegend.backgroundColor = [MyColor gray25];
self.chartView.legend = self.chartLegend;
[self.view addSubview:self.chartLegend];

In another function I am adding my IGLineSeries to my chart:

IGCategorySeriesDataSourceHelper *categorySource = [[IGCategorySeriesDataSourceHelper alloc] init];
categorySource.data = lineChartArr;
categorySource.valuePath = @"close";
categorySource.labelPath = @"date";

        lineSeries = [[IGLineSeries alloc] initWithKey:@"chartSeries"];

        lineSeries.xAxis = xAxis;

        lineSeries.yAxis = yAxis;

        lineSeries.yAxis.minimum = -20;

        lineSeries.yAxis.maximum = 20;

        lineSeries.dataSource = categorySource;

        lineSeries.xAxis.majorStrokeThickness = 0.6f;

        lineSeries.yAxis.majorStrokeThickness = 0.6f;

        lineSeries.xAxis.majorStroke = [[IGBrush alloc]initWithColor:[MyColor gray25]];

        lineSeries.yAxis.majorStroke = [[IGBrush alloc]initWithColor:[MyColor gray25]];

        lineSeries.title = title;

        lineSeries.legendItemIsVisible = YES;

        lineSeries.legend = self.chartLegend;

        [self.chartView addSeries:lineSeries];

So what am I doing wrong? These codes only display a gray view without the titles. Thanks for your answers.

Parents
  • 21382
    posted

    I looked over your code but didn't see anything obvious that would prevent the legends from showing.  Attached is a sample showing a mock up of how they work.  

    Please modify it to show the behavior you are seeing.

    LegendDemo.zip
Reply Children