Remove exporting button from HighChart Objective-C - objective-c

Is there anyway to remove the exporting button from the line chart in iOS ?
Below is my code :
HIChartView *chartView = [[HIChartView alloc] initWithFrame:self.lineGraphView2.bounds];
chartView.tintColor = [UIColor greenColor];
HIColor *color = [[HIColor alloc] initWithHexValue:#"283445"];
HIColor *greeColorHex = [[HIColor alloc] initWithHexValue:#"00B84A"];
HIColor *redColorHex = [[HIColor alloc] initWithHexValue:#"A3001F"];
// color = [color initWithHexValue:#"000000"];
HIChart *chart = [[HIChart alloc] init];
chart.plotBackgroundColor = color;
chart.backgroundColor = color;
HICredits *credits = [[HICredits alloc] init];
credits.enabled = #0;
HIExporting *exporting = [[HIExporting alloc] init];
exporting.enabled = #0;
HIOptions *options = [[HIOptions alloc]init];
options.exporting.enabled = false;
HITitle *title = [[HITitle alloc]init];
title.text = #"";
HISubtitle *subtitle = [[HISubtitle alloc]init];
// subtitle.text = #"Source: thesolarfoundation.com";
HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = #"";
yaxis.gridLineColor = color;
yaxis.gridLineWidth = #0;
HILegend *legend = [[HILegend alloc]init];
legend.layout = #"vertical";
legend.align = #"right";
legend.verticalAlign = #"middle";
HIPlotOptions *plotoptions = [[HIPlotOptions alloc] init];
plotoptions.series = [[HISeries alloc] init];
plotoptions.series.label = [[HILabel alloc] init];
plotoptions.series.label.connectorAllowed = [[NSNumber alloc] initWithBool:false];
plotoptions.series.lineWidth = #2;
HILine *line1 = [[HILine alloc]init];
line1.name = #"Shares Price";
line1.data = graphPointsMutableArray;
line1.color = greeColorHex;
line1.threshold = #10;
HIResponsive *responsive = [[HIResponsive alloc] init];
HIRules *rules1 = [[HIRules alloc] init];
rules1.condition = [[HICondition alloc] init];
rules1.chartOptions = #{
#"legend" : #{
#"layout": #"horizontal",
#"align": #"center",
#"verticalAlign": #"bottom"
}
};
responsive.rules = [NSMutableArray arrayWithObjects:rules1, nil];
options.title = title;
options.subtitle = subtitle;
options.yAxis = [NSMutableArray arrayWithObject:yaxis];
options.legend = legend;
options.plotOptions = plotoptions;
options.series = [NSMutableArray arrayWithObjects:line1, nil];
options.responsive = responsive;
options.chart = chart;
options.credits = credits;
options.exporting = exporting;
options.exporting.enabled = #0;
options.labels.enabled = #0;
chartView.options = options;
[self.lineGraphView2 addSubview:chartView];
I have read in the documentation to set exporting.enable = false but it's not working.

in viewForHeaderInSection method set exporting = NO
it will hide 3 bars button. see below screenshot for more details :

Below is the solution I found in Swift. Basically, you have to create a HINavigation object, and a HIButtonOptions object. After setting the button options enabled property to false, you set the navigation's button options property to the button options object, and then set your HIOptions object's navigation object to the navigation object you created. My obj-c isn't good enough to try typing it out in obj-c, so below is the Swift version of my solution:
// init your options object
let options = HIOptions()
// hide hamburger button
let navigation = HINavigation() // init navigation object
let buttonOptions = HIButtonOptions() // init button options object
buttonOptions.enabled = false
navigation.buttonOptions = buttonOptions
options.navigation = navigation

you set the exporting to false a couple of times, change that so it is set only one time like that in swift:
options.exporting = HIExporting()
options.exporting.enabled = NSNumber.init(booleanLiteral: false)

Related

AVPlayerViewController info view which shows external meta data does not remove from view on menu press on apple tv remote

I am setting external metadata item using below code and it is working properly but the problem I am facing is when controller is pop using apple TV remote menu that info view still exist.
AVMutableMetadataItem *titleMetadataItem = [[AVMutableMetadataItem alloc] init];
titleMetadataItem.locale = [NSLocale currentLocale];
titleMetadataItem.key = AVMetadataCommonKeyTitle;
titleMetadataItem.keySpace = AVMetadataKeySpaceCommon;
titleMetadataItem.value = #"Some value";
AVMutableMetadataItem *descriptionMetadataItem = [[AVMutableMetadataItem alloc] init];
descriptionMetadataItem.locale = [NSLocale currentLocale];
descriptionMetadataItem.identifier = AVMetadataIdentifierQuickTimeMetadataInformation;
descriptionMetadataItem.value = #"Some value";
AVMutableMetadataItem *artworkMetadataItem = [[AVMutableMetadataItem alloc] init];
artworkMetadataItem.locale = [NSLocale currentLocale];
artworkMetadataItem.key = AVMetadataCommonKeyArtwork;
artworkMetadataItem.keySpace = AVMetadataKeySpaceCommon;
NSArray *metadataArray = [[NSArray alloc] initWithObjects:titleMetadataItem,descriptionMetadataItem,artworkMetadataItem, nil];
self.playerItem.externalMetadata = metadataArray;
I am adding AVPlayerViewController view as subview on UIViewController view.

Not see image after shared article to Facebook with FBSDKShareOpenGraphObject

I try to shared image to Facebook and I need that the app name was be in the shared post in Facebook
this is the code :
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
UIImage *image1 = [GeneralMethods imageConvertToSizeWithImage:postImageView.image scaledToWidth:300];
photo.image = [UIImage imageNamed:#"VImage.png"];
photo.userGenerated = YES;
NSDictionary *properties = #{
#"og:type": #"article",
#"og:title": #"new item",
#"og:description": #"bla bla",
// #"og:image": #[photo],
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// [object setPhoto:photo forKey:#"og:image"];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"news.publishes";
[action setObject:object forKey:#"article"];
// Add the photo to the action. Actions
// can take an array of images.
[action setArray:#[photo] forKey:#"image"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
[FBSDKShareDialog showFromViewController:ParetDelaget withContent:content delegate:self];
this is Facebook preview page with the image i add:
this is the post in my Facebook wall without image :
whats I do wrong ?
Uncomment this line:
// #"og:image": #[photo],
And comment this one:
[action setArray:#[photo] forKey:#"image"];
Like this you will have both image, title and description showing.
A little remark: the photo object must be a string URL
In my case, here is the resulting code:
// Create an object
NSDictionary *properties = #{
#"og:type": #"article",
#"og:url": #"https://the_link_you_want.com",
#"og:title": #"your title",
#"og:description": #"your description",
#"og:image": #"http://url_to_your_image"
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"news.publishes";
[action setObject:object forKey:#"article"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
[shareDialog show];
if (![shareDialog canShow]) {
// update the app UI accordingly
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
NSLog(#"FB Error: %#", error);
}
Hope that helps

Build a factory method to create QuickDialog Entry Elements bound to view model with RAC

I'm building a rather long form with QuickDialog and Reactive Cocoa and I would love to be able to write a factory method to setup my QElements from the same form.
Here's my example of how I'm doing it now.
self.root = [[QRootElement alloc] init];
self.root.title = self.title;
self.root.grouped = YES;
self.basic = [[QSection alloc] init];
self.basic.title = #"Basic Information";
[self.root addSection:self.basic];
QEntryElement *address = [[QEntryElement alloc] init];
address.title = #"Address";
RAC(address, textValue) = [RACObserve(self, viewModel.address) distinctUntilChanged];
RAC(self, viewModel.address) = [RACObserve(address, textValue) distinctUntilChanged];
[self.basic addElement:address];
QEntryElement *city = [[QEntryElement alloc] init];
city.title = #"City";
RAC(city, textValue) = [RACObserve(self, viewModel.city) distinctUntilChanged];
RAC(self, viewModel.city) = [RACObserve(city, textValue) distinctUntilChanged];
[self.basic addElement:city];
QEntryElement *state = [[QEntryElement alloc] init];
state.title = #"State";
RAC(state, textValue) = [RACObserve(self, viewModel.state) distinctUntilChanged];
RAC(self, viewModel.state) = [RACObserve(state, textValue) distinctUntilChanged];
[self.basic addElement:state];
QEntryElement *postal = [[QEntryElement alloc] init];
postal.title = #"Zip";
RAC(postal, textValue) = [RACObserve(self, viewModel.postalCode) distinctUntilChanged];
RAC(self, viewModel.postalCode) = [RACObserve(postal, textValue) distinctUntilChanged];
[self.basic addElement:postal];
QEntryElement *phone = [[QEntryElement alloc] init];
phone.title = #"Phone";
RAC(phone, textValue) = [RACObserve(self, viewModel.phoneNumber) distinctUntilChanged];
RAC(self, viewModel.phoneNumber) = [RACObserve(phone, textValue) distinctUntilChanged];
[self.basic addElement:phone];
I would like to be able to call a method like:
-(QEntryElement *)racEntryElementWithTitle:(NSString *)title andModel(ViewModel *)model andProperty:(NSString*)property;
Is there some way to do this?
Generally, if you want two-way data binding, you should use a RACChannel, so you don't have to explicitly use -distinctUntilChanged to prevent the two-way data binding infinite loop. To do this with KVO, you create two RACChannels (one for each KVO'd property) and assign one channel's followingTerminal to the other's followingTerminal property. This is normally done for you by the RACChannelTo() macro, but if you want to dynamically supply the key paths as NSStrings, you can't use that macro; you need to dive in and use the RACKVOChannel class directly:
(This code is untested.)
- (QEntryElement *)entryElementWithTitle:(NSString *)title boundWithModel(ViewModel *)model atKeyPath:(NSString*)keyPath
{
QEntryElement *ee = [[QEntryElement alloc] init];
ee.title = title;
RACChannel *modelChannel = [[RACKVOChannel alloc] initWithTarget:model keyPath:keyPath nilValue:#""];
RACChannelTo(ee, textValue, #"") = modelChannel.followingTerminal;
return ee;
}
// later...
self.root = [[QRootElement alloc] init];
self.root.title = self.title;
self.root.grouped = YES;
self.basic = [[QSection alloc] init];
self.basic.title = #"Basic Information";
[self.root addSection:self.basic];
[self.basic addElement:[self entryElementWithTitle:#"Address" boundWithModel:self.viewModel atKeyPath:#"address"];
[self.basic addElement:[self entryElementWithTitle:#"City" boundWithModel:self.viewModel atKeyPath:#"city"];
[self.basic addElement:[self entryElementWithTitle:#"State" boundWithModel:self.viewModel atKeyPath:#"state"];
[self.basic addElement:[self entryElementWithTitle:#"Zip" boundWithModel:self.viewModel atKeyPath:#"postalCode"];
[self.basic addElement:[self entryElementWithTitle:#"Phone" boundWithModel:self.viewModel atKeyPath:#"phoneNumber"];
The problem you are no doubt facing is those macros. One approach to this would be to run the preprocessor to see what the output of the macro looks like.
Fore example, this line:
RAC(postal, textValue) = [RACObserve(self, viewModel.postalCode) distinctUntilChanged];
Expands to the following:
[[RACSubscriptingAssignmentTrampoline alloc] initWithTarget:(postal) nilValue:(((void *)0))][#(((void)(__objc_no && ((void) postal. textValue, __objc_no)), "textValue"))] = [[(id)(self) rac_valuesForKeyPath:#(((void)(__objc_no && ((void)self.viewModel.postalCode, __objc_no)), "viewModel.postalCode")) observer:self] distinctUntilChanged];
This should allow you to parameterise the parts you require.

Change a Property for All Objects in an NSMutableArray

I have an NSMutableArray with 9 objects. Those objects have many properties, like questionName, questionWhatRow, etc.
I want to be able to change one of those properties for All of the objects in the NSMutableArray.
Here is my NSMutableArray Class.
-(id) init
{
self = [super init];
if (self)
{
self.questionsArray = [[NSMutableArray alloc] init];
Question *newQuestion = [[Question alloc] init];
newQuestion.questionName = #"What is the name of the girl who has to fetch water for her family every day?";
newQuestion.questionRowName = #"Question 1";
newQuestion.questionAnswer = #"Nya";
newQuestion.questionHint = #"Maybe if you read the book you would know";
newQuestion.questionWhatRow = #"Nya";
newQuestion.questionCompleteOrNot = #"No";
newQuestion.pointForQuestion = 1;
[self.questionsArray addObject:newQuestion];
newQuestion = [[Question alloc] init];
newQuestion.questionName = #"What is Nya's sister's name?";
newQuestion.questionRowName = #"Question 2";
newQuestion.questionAnswer = #"Akeer";
newQuestion.questionHint = #"Maybe if you read the book you would know";
newQuestion.questionWhatRow = #"Nya";
newQuestion.questionCompleteOrNot = #"No";
newQuestion.pointForQuestion = 1;
[self.questionsArray addObject:newQuestion];
newQuestion = [[Question alloc] init];
newQuestion.questionName = #"What people is Nya's mother scared of when her father and sons go hunting?";
newQuestion.questionRowName = #"Question 3";
newQuestion.questionAnswer = #"Dinka";
newQuestion.questionHint = #"Maybe if you read the book you would know";
newQuestion.questionWhatRow = #"Nya";
newQuestion.questionCompleteOrNot = #"No";
newQuestion.pointForQuestion = 1;
[self.questionsArray addObject:newQuestion];
newQuestion = [[Question alloc] init];
newQuestion.questionName = #"What is Salva scared of when he is in the Akobo desert?";
newQuestion.questionRowName = #"Question 4";
newQuestion.questionAnswer = #"Lions";
newQuestion.questionHint = #"He is scared of an animal because it ate his friend Marial";
newQuestion = nil;
}
return self;
}
-(NSUInteger)count
{
return questionsArray.count;
}
- (Question *)questionAtIndex:(NSUInteger)index
{
return [questionsArray objectAtIndex:index];
}
Now, I have another class called ScoreViewController, and I want to be able to change the property, questionCompleteOrNot of the NSMutableArray questionsArray for all objects/questions to #"No".
My ScoreView has a button to Reset, but I don't know what to put in it to change all questionCompleteOrNot properties of the questionsArray to #"No".
Sorry for the long question, I was trying to be very specific.
Edit
Here is my DetailView for a tableView.
if ([[selectedQuestion questionCompleteOrNot] isEqualToString:#"No"])
{
if ([[selectedQuestion questionAnswer] caseInsensitiveCompare:answerField.text] == NSOrderedSame)
{
// Show the correct label
[correctLabel setHidden:NO];
correctLabel.text = #"Correct!";
correctLabel.textColor = [UIColor greenColor];
}
else
{
// Show the incorrect label
[correctLabel setHidden:NO];
correctLabel.text = #"Incorrect";
correctLabel.textColor = [UIColor redColor];
[incorrectPlayer play];
[[selectedQuestion questionCompleteOrNot] isEqualToString:#"Yes"];
}
// Erase the text in the answerField
answerField.text = #"";
}
if ([[selectedQuestion questionCompleteOrNot] isEqualToString:#"Yes"])
{
UIAlertView *error = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"You already answered this question. Please click the reset button on the score view to restart."
delegate:self
cancelButtonTitle:#"Okay!"
otherButtonTitles:nil];
[error show];
answerField.text = #"";
}
selectedQuestion.questionCompleteOrNot = #"Yes";
correctLabel.text = #"";
NSLog(#"Selected question's questionCompleteOrNot is %#", [selectedQuestion questionCompleteOrNot]);
You can use NSArray's makeObjectsPerformSelector:withObject:, like so:
[questionsArray makeObjectsPerformSelector:#selector(setQuestionCompleteOrNot:) withObject:#"No"];

Core-Plot unable to plot multiple graphs on one page (iPad)

I am trying to display multiple chart's on one screen but i am not able to get it to work. I am trying to get to a point where i have 3 x pieGraphs and 1 x scattered graph on this display.
I have tried: Unable to have two CorePlot graphs show simultaneously but not been able to solve this. I am using the example app from Core-Plot as a base for the design of the code. I see no difference when i try to emulate the solution to that problem in my code.
I am able to display the first pie chart: "matchPieChart" but not the second one "questionsPieChart". It does not look like it even process the second chart.
Without consideration of the other similar problem solution (above) the result is:
The legend on the right side is the one that is associated with the pie that is displayed to the left, i guess it hook up to the second pie that i try to display. It is displayed where the second pie chart should be displayed.
Here is the code execution, see the NSLog in the code:
iPad_matchPieChartConfiguration
numberOfRecordsForPlot:
numberOfRecordsForPlot:
numberForPlot:
numberForPlot:
numberOfRecordsForPlot:
numberOfRecordsForPlot:
legendTitleForPieChart: matchPieChart
legendTitleForPieChart: matchPieChart
iPad_questionsPieChartConfiguration
legendTitleForPieChart: matchPieChart
legendTitleForPieChart: matchPieChart
legendTitleForPieChart: matchPieChart
legendTitleForPieChart: matchPieChart
dataLabelForPlot:
dataLabelForPlot: matchPieChart
dataLabelForPlot:
dataLabelForPlot: matchPieChart
legendTitleForPieChart: matchPieChart
legendTitleForPieChart: matchPieChart
legendTitleForPieChart: matchPieChart
legendTitleForPieChart: matchPieChart
And here is the actual code:
-(void)iPad_matchPieChartConfiguration {
NSLog(#"iPad_matchPieChartConfiguration");
// Set titles
playerName_label.text = playerName;
myString = [[NSString alloc]initWithFormat:#"Total number of Games played: %.0f", nrGamesPlayed];
title_Matches_label.text = myString;
//Create host view
matchChartView = [[CPTGraphHostingView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
[self.view addSubview:matchChartView];
matchPieGraph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
matchChartView.hostedGraph = matchPieGraph;
matchPieGraph.plotAreaFrame.masksToBorder = NO;
matchPieGraph.paddingLeft = 10.0;
matchPieGraph.paddingTop = 120.0;
matchPieGraph.paddingRight = 350.0;
matchPieGraph.paddingBottom = 360.0;
matchPieGraph.axisSet = nil;
//====ADD MATCH PIE CHART====//
matchPiePlot = [[CPTPieChart alloc]init];
matchPiePlot.dataSource = self;
matchPiePlot.pieRadius = 100.0;
matchPiePlot.identifier = #"matchPieChart";
matchPiePlot.startAngle = M_PI_4;
matchPiePlot.sliceDirection = CPTPieDirectionCounterClockwise;
matchPiePlot.borderLineStyle = [CPTLineStyle lineStyle];
matchPiePlot.labelOffset = 5.0;
matchPieGraph.titleTextStyle = whiteText;
[matchPieGraph addPlot:matchPiePlot];
// 1 - Get graph instance
CPTGraph *matchGraph = matchChartView.hostedGraph;
// 2 - Create legend
CPTLegend *theMatchLegend = [CPTLegend legendWithGraph:matchGraph];
// 3 - Configure legen
CPTMutableTextStyle *legendMatchTextStyle = [CPTTextStyle textStyle];
legendMatchTextStyle.fontSize = 12.0f;
legendMatchTextStyle.fontName = #"Noteworthy-Bold";
legendMatchTextStyle.color = [CPTColor whiteColor];
theMatchLegend.numberOfColumns = 2;
theMatchLegend.fill = nil;
theMatchLegend.borderLineStyle = nil;
theMatchLegend.cornerRadius = 5.0;
theMatchLegend.textStyle = legendMatchTextStyle;
// 4 - Add legend to graph
matchGraph.legend = theMatchLegend;
matchGraph.legendAnchor = CPTRectAnchorRight;
matchGraph.legendDisplacement = CGPointMake(-460.0, -10.0);
}
-(void)iPad_questionsPieChartConfiguration {
NSLog(#"iPad_questionsPieChartConfiguration");
// Set titles
playerName_label.text = playerName;
myString = [[NSString alloc]initWithFormat:#"Total number of Questions answered: %.0f", nrQuestionsAnswered];
title_Questions_label.text = myString;
//Create host view
questionsChartView = [[CPTGraphHostingView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
[self.view addSubview:questionsChartView];
questionsPieGraph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
questionsChartView.hostedGraph = matchPieGraph;
questionsPieGraph.plotAreaFrame.masksToBorder = NO;
questionsPieGraph.paddingLeft = 10.0;
questionsPieGraph.paddingTop = 120.0;
questionsPieGraph.paddingRight = 150.0;
questionsPieGraph.paddingBottom = 360.0;
questionsPieGraph.axisSet = nil;
//====ADD MATCH PIE CHART====//
questionsPiePlot = [[CPTPieChart alloc]init];
questionsPiePlot.dataSource = self;
questionsPiePlot.pieRadius = 100.0;
questionsPiePlot.identifier = #"questionsPieChart";
questionsPiePlot.startAngle = M_PI_4;
questionsPiePlot.sliceDirection = CPTPieDirectionCounterClockwise;
questionsPiePlot.borderLineStyle = [CPTLineStyle lineStyle];
questionsPiePlot.labelOffset = 5.0;
questionsPieGraph.titleTextStyle = whiteText;
[questionsPieGraph addPlot:questionsPiePlot];
// 1 - Get graph instance
CPTGraph *questionsGraph = questionsChartView.hostedGraph;
// 2 - Create legend
CPTLegend *theQuestionsLegend = [CPTLegend legendWithGraph:questionsGraph];
// 3 - Configure legen
CPTMutableTextStyle *legendQuestionsTextStyle = [CPTTextStyle textStyle];
legendQuestionsTextStyle.fontSize = 12.0f;
legendQuestionsTextStyle.fontName = #"Noteworthy-Bold";
legendQuestionsTextStyle.color = [CPTColor whiteColor];
theQuestionsLegend.numberOfColumns = 2;
theQuestionsLegend.fill = nil;
theQuestionsLegend.borderLineStyle = nil;
theQuestionsLegend.cornerRadius = 5.0;
theQuestionsLegend.textStyle = legendQuestionsTextStyle;
// 4 - Add legend to graph
questionsGraph.legend = theQuestionsLegend;
questionsGraph.legendAnchor = CPTRectAnchorRight;
questionsGraph.legendDisplacement = CGPointMake(-160.0, -10.0);
}
- (void)viewDidLoad {
[super viewDidLoad];
playerName_label.text = playerName;
AccessPlayerData *checkPlayerDiffFunction = [AccessPlayerData new];
int diffLevel = [checkPlayerDiffFunction checkPlayersDifficultyLevel:playerName];
switch (diffLevel) {
case 1:
playerDifficulty_label.text = #"Difficuly Level: Children / Easy";
break;
case 2:
playerDifficulty_label.text = #"Difficuly Level : Teenager / Medium";
break;
case 3:
playerDifficulty_label.text = #"Difficuly Level: Adult / Hard";
break;
default:
break;
}
nrGamesPlayed_label.text = [NSString stringWithFormat:#"Total number of games played: %.0f", nrGamesPlayed];
//====IF THIS IS IPAD PROCESS ALL GRAPHS====//
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
double nrOfSingleGames = nrGamesPlayed -(nrGamesWon + nrGamesLost);
double nrOfTotalGames = nrGamesPlayed;
double percentageNrOfSingleGames = (nrOfSingleGames / nrOfTotalGames) * 100;
double percentageNrOfMatchGames = ((nrOfTotalGames - nrOfSingleGames) / nrOfTotalGames) * 100;
NSString *singleGames = [[NSString alloc]initWithFormat:#"%.0f (%.0f%%)", nrOfSingleGames, percentageNrOfSingleGames];
NSString *matchesGames = [[NSString alloc]initWithFormat:#"%.0f (%.0f%%)", (nrOfTotalGames - nrOfSingleGames), percentageNrOfMatchGames];
//=========ADD DATA FOR MATCHES PIE GRAPH==========//
NSMutableArray *contentMatchArray = [NSMutableArray arrayWithObjects:[NSNumber numberWithDouble:nrOfSingleGames], [NSNumber numberWithDouble:(nrOfTotalGames - nrOfSingleGames)], nil];
labelMatchOrder = [[NSArray alloc]initWithObjects:singleGames, matchesGames, nil];
legendMatchOrder = [[NSArray alloc] initWithObjects:#"Single Games", #"Matches", nil];
self.dataForMatchChart = contentMatchArray;
//=========ADD DATA FOR QUESTIONS PIE GRAPH==========//
nrQuestionsWrongAnswers = nrQuestionsAnswered - nrQuestionsCorrectAnswered;
double percentageCorrectAnswers = (nrQuestionsCorrectAnswered / nrQuestionsAnswered) * 100;
double percentageWrongAnswers = (nrQuestionsWrongAnswers / nrQuestionsAnswered) * 100;
NSString *answerCorrect = [[NSString alloc]initWithFormat:#"%.0f (%.0f%%)", nrQuestionsCorrectAnswered, percentageCorrectAnswers];
NSString *answerWrong = [[NSString alloc]initWithFormat:#"%.0f (%.0f%%)", nrQuestionsWrongAnswers, percentageWrongAnswers];
playerName_label.text = playerName;
myString = [[NSString alloc]initWithFormat:#"Total number of questions answered: %.0f",nrQuestionsAnswered];
title_Questions_label.text = myString;
NSMutableArray *contentQuestionsArray = [NSMutableArray arrayWithObjects:[NSNumber numberWithDouble:nrQuestionsWrongAnswers], [NSNumber numberWithDouble:nrQuestionsCorrectAnswered], nil];
labelQuestionsOrder = [[NSArray alloc]initWithObjects:answerWrong, answerCorrect, nil];
legendQuestionsOrder = [[NSArray alloc] initWithObjects:#"Correct answers", #"Wrong answers", nil];
self.dataForQuestionsChart = contentQuestionsArray;
NSLog(#"ContentQuestionsArray: %#", contentQuestionsArray);
//====SET GLOBAL PARAMETERS FOR THE GRAPHs====//
whiteText = [CPTMutableTextStyle textStyle];
whiteText.color = [CPTColor whiteColor];
whiteText.fontSize = 14;
whiteText.fontName = #"Noteworthy-Bold";
[self iPad_matchPieChartConfiguration];
[self iPad_questionsPieChartConfiguration];
}
}
#pragma mark -
#pragma mark Plot Data Source Methods
-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index {
if ( [matchPiePlot.identifier isEqual:[NSString stringWithFormat:#"matchPieChart"]] ) {
NSLog(#"legendTitleForPieChart: matchPieChart");
if (index < [legendMatchOrder count]) {
return [legendMatchOrder objectAtIndex:index];
}
}
else if ( [matchPiePlot.identifier isEqual:[NSString stringWithFormat:#"questionsPieChart"]] ) {
NSLog(#"legendTitleForPieChart: questionsPieChart");
}
return #"N/A";
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
NSLog(#"numberOfRecordsForPlot:");
if ([plot isKindOfClass:[CPTPieChart class]]) {
return [dataForMatchChart count];
}
else {
return 10; //>>>dummy
}
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
NSLog(#"numberForPlot:");
NSDecimalNumber *num = nil;
if ([plot isKindOfClass:[CPTPieChart class]]) {
if (index >= [dataForMatchChart count]) {
return nil;
}
if (fieldEnum == CPTPieChartFieldSliceWidth) {
num = [dataForMatchChart objectAtIndex:index];
}
else {
num = (NSDecimalNumber *) [NSDecimalNumber numberWithUnsignedInteger:index];
}
}
return num;
}
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
NSLog(#"dataLabelForPlot:");
CPTTextLayer *label = nil;
if ( [plot.identifier isEqual:[NSString stringWithFormat:#"matchPieChart"]] ) {
NSLog(#"dataLabelForPlot: matchPieChart");
label = [[CPTTextLayer alloc] initWithText:[labelMatchOrder objectAtIndex:index]];
CPTMutableTextStyle *textStyle = [label.textStyle mutableCopy];
matchPiePlot.labelOffset = -80;
textStyle.fontName = #"Noteworthy-Bold";
textStyle.color = [CPTColor whiteColor];
textStyle.fontSize = 16;
label.textStyle = textStyle;
return label;
}
else if ( [plot.identifier isEqual:[NSString stringWithFormat:#"matchPieChart"]] ) {
NSLog(#"dataLabelForPlot: MATCH");
}
return label;
}
//====SET COLOR FOR SLICES IN PIE GRAPH====//
-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index {
// For index = 0
double red1 = 222.0;
double green1 = 184.0;
double blue1 = 135.0;
float alpha1 = 0.5f;
double red2 = 155.0;
double green2 = 00.0;
double blue2 = 0.0;
float alpha2 = 0.3f;
if (index == 0) {
CPTFill *fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:red1 green:green1 blue:blue1 alpha:alpha1]];
return fill;
}
if (index == 1) {
CPTFill *fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:red2 green:green2 blue:blue2 alpha:alpha2]];
return fill;
}
return 0;
}
I am really struggling with this and would appreciate help :-)
Change this line
questionsChartView.hostedGraph = matchPieGraph;
to
questionsChartView.hostedGraph = questionsPieGraph;
Also, check how the two hosting views are laid out within their superview (self.view). Make sure both are visible and positioned correctly.