Reputation: 24
I'm using an iOS charting software called TWRCharts, and I'm trying to add multiple charts in the same view controller. I have added UIViews using Interface Builder, and connected them using outlets in my .h file. When I try showing one chart, my main chart, it shows fine. But when I try adding more charts, they don't appear. I have tried reversing the order of chart drawing, and in this case one of the smaller charts appears, but nothing else. When I try adding multiple subviews to their respective views, nothing appears. Here are my .h and .m files.
.h
#import <UIKit/UIKit.h>
#import "TWRChart.h"
@interface OverviewViewController : UIViewController
- (IBAction)didTapButton:(id)sender;
@property (strong, nonatomic) IBOutlet UIView *mainCircularChartUIView;
@property (strong, nonatomic) TWRChartView *mainCircularChart;
@property (strong, nonatomic) IBOutlet UIView *tapTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *tapTestCircularChart;
@property (strong, nonatomic) IBOutlet UIView *cogTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *cogTestCircularChart;
@property (strong, nonatomic) IBOutlet UIView *voiceTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *voiceTestCircularChart;
@property (strong, nonatomic) IBOutlet UIView *mentalHealthTestControllerUIView;
@property (strong, nonatomic) TWRChartView *mentalHealthTestController;
@end
.m (currently commenting out adding more than one subview)
- (void)viewDidLoad {
[super viewDidLoad];
/////////// Main Circular Chart View ////////////////////////
self.mainCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 60, 300, 300)];
self.mainCircularChart.backgroundColor = [UIColor clearColor];
self.mainCircularChart.userInteractionEnabled = YES;
// Add the chart view to the controller's view
[self.mainCircularChartUIView addSubview:self.mainCircularChart];
/////////// Sub Circular Chart Views ////////////////////////
self.tapTestCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];
self.tapTestCircularChart.backgroundColor = [UIColor clearColor];
self.tapTestCircularChart.userInteractionEnabled = YES;
self.cogTestCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];
self.cogTestCircularChart.backgroundColor = [UIColor clearColor];
self.cogTestCircularChart.userInteractionEnabled = YES;
// Add the chart view to the controller's view
// [self.tapTestCircularChartUIView addSubview:self.tapTestCircularChart];
// [self.cogTestCircularChartUIView addSubview:self.cogTestCircularChart];
[self loadMainCircularChart];
[self loadSubCircularCharts];
}
- (void)loadSubCircularCharts {
// Values
NSArray *values = @[@20, @30, @15, @5];
// Colors
UIColor *color1 = [UIColor colorWithHue:0.5 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color2 = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color3 = [UIColor colorWithHue:0.7 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color4 = [UIColor colorWithHue:0.8 saturation:0.6 brightness:0.6 alpha:1.0];
NSArray *colors = @[color1, color2, color3, color4];
// Tap Test Chart ///////////////////////////////////////////
TWRCircularChart *tapTestChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];
[self.tapTestCircularChart loadCircularChart:tapTestChart];
// Cog Test Chart ///////////////////////////////////////////
TWRCircularChart *cogTestChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];
//
[self.tapTestCircularChart loadCircularChart:cogTestChart];
}
- (void)loadMainCircularChart {
// Values
NSArray *values = @[@20, @30, @15, @5];
// Colors
UIColor *color1 = [UIColor colorWithHue:0.5 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color2 = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color3 = [UIColor colorWithHue:0.7 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color4 = [UIColor colorWithHue:0.8 saturation:0.6 brightness:0.6 alpha:1.0];
NSArray *colors = @[color1, color2, color3, color4];
// Doughnut Chart
TWRCircularChart *pieChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];
[self.mainCircularChart loadCircularChart:pieChart];
}
Upvotes: 0
Views: 1083
Reputation: 605
You can have two ways to implement
if you have problem in using scroll view then
Upvotes: 1
Reputation: 559
Have you added a UIScrollView as main subview of your VC? Without a scrollview, your content won't scroll
Upvotes: 0