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.
found the answer, chartLegend.orientation = IGOrientationVertical;
Thank you Darrell again.
Thank you so much Darrell; [IGChartDefaultThemes DefaultTheme] worked for me. Also just a quick one, how can I list the items vertically on the IGLegend? Thank you.
Short version :
Instead of setting the .theme property to nil , set it to the default theme
chartView.theme = [IGChartDefaultThemes DefaultTheme];
//chartView.theme = nil;
Long version:
In the application code, a blank theme is being created and a few properties are being set. When that is nilled out later, there isn't any style information for the legend, so when rendering happens, the legend is blanked out. So rather than nil, go back to the default theme since that is probably what you are trying to do anyway.
Hi Darrell,
I have created a sample project. I tried to replicate my current project and IGLegend doesn't work in this sample too. If you could check the attached sample project and give me some suggestions to fix this issue I will be pleased. Thank you again.
Whether this is a bug or not is something we won't be able to discern without a sample.
I am going to ask again, can you either modify the sample I sent you to reproduce the behavior or create a small sample that shows the behavior.
We cannot determine what is causing the issue without being able to see the issue. If it is a bug we would need a sample so we can track down the behavior. If it's not a bug but a sample issue, we wouldn't be able to tell without looking at code.
My only other guess is that when you are swapping out your items you are disconnecting the legend from the chart. But that is only a guess.