Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8446393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:55:14+00:00 2026-06-10T09:55:14+00:00

I am trying to display multiple chart’s on one screen but i am not

  • 0

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:

Result without suggestion (current)

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:55:16+00:00Added an answer on June 10, 2026 at 9:55 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use getResources to display multiple resources withing one resource, including
I am trying to display the status of multiple claims from one day at
I have being trying to display the filenames for the multiple files that have
Ok, so I'm trying to use Sherlock to display multiple tabs, each for one
I am trying to display multiple li's under a ul. But by using the
I'm trying to get a drop down list to display multiple columns from a
I am trying to display multiple icons to the Treeview item but it is
I have a for loop that I'm trying to display multiple popups with. I
I am trying to display 3 Highcharts-generated graphs on one page. I have loaded
I can get one successful Open Flash Chart per view. I'm now trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.