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 8407183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:17:52+00:00 2026-06-09T23:17:52+00:00

I am totally new to Core Plot and I am not able to add

  • 0

I am totally new to Core Plot and I am not able to add a Legend to my view. I have been trying all kinds of tutorial’s and read a lot of information but am i do not understand how to display the legend.

I would really appreciate some help as i have been spending quite some time to try to get this to work.

Be aware that my aim at this point is to display a legend such as:

What i want

Here is what i get:

The Legend as it look now

The only thing that show up is the while little thick line on the right. I can move that but not get the legend.

The code:

// Create pieChart from theme
pieChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[pieChart applyTheme:theme];

//Create host view
self.hostingView = [[CPTGraphHostingView alloc] 
                    initWithFrame:[[UIScreen mainScreen]bounds]];
[self.view addSubview:self.hostingView];

hostingView_.hostedGraph = pieChart;
pieChart.axisSet = nil;
pieChart.plotAreaFrame.borderLineStyle = nil; 

pieChart.paddingLeft   = 10.0;
pieChart.paddingTop    = 120.0;
pieChart.paddingRight  = 10.0;
pieChart.paddingBottom = 80.0;

pieChart.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
pieChart.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]];

CPTMutableTextStyle *whiteText = [CPTMutableTextStyle textStyle];
whiteText.color = [CPTColor whiteColor];
whiteText.fontSize = 14;
whiteText.fontName = @"Helvetica";

pieChart.titleTextStyle = whiteText;




//==================================================//
// LEGENDS //

// 1 - Get graph instance
CPTGraph *graph = self.hostingView.hostedGraph;
// 2 - Create legend
CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];
// 3 - Configure legen
theLegend.numberOfColumns = 1;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;
// 4 - Add legend to graph
graph.legend = theLegend;     
graph.legendAnchor = CPTRectAnchorRight;
CGFloat legendPadding = -(self.view.bounds.size.width / 8);
graph.legendDisplacement = CGPointMake(legendPadding, 0.0);




//==================================================//





// Add pie chart
CPTPieChart *piePlot = [[CPTPieChart alloc] init];
piePlot.dataSource      = self;
piePlot.pieRadius       = 70.0; //140.0;  //131.0;
piePlot.identifier      = @"Pie Chart 1";
piePlot.startAngle      = M_PI_4;
piePlot.sliceDirection  = CPTPieDirectionCounterClockwise;   //CPTPieDirectionCounterClockwise;
piePlot.centerAnchor    = CGPointMake(0.5, 0.5); //(0.5, 0.38);
piePlot.borderLineStyle = [CPTLineStyle lineStyle];


piePlot.delegate        = self;
[pieChart addPlot:piePlot];

xx

-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index {
return [NSString stringWithFormat:@"Pie Slice %lu", (unsigned long)index];
}
  • 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-09T23:17:53+00:00Added an answer on June 9, 2026 at 11:17 pm

    Add the plot to the graph before you set up the legend. You could also use the -addPlot: method on the legend directly, but it’s easier to let the graph do it.

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

Sidebar

Related Questions

I'm totally new to Ruby but not to programming. All I did was going
I'm totally baffled why this is not working. I'm trying to insert a new
Totally new to programming so kindly excuse the silly question. I have this URL
Totally new to Capistrano. I have a local git repository that I want to
im totally new when it comes to trying to make HTML code. I was
I'm totally new to AWS. I managed to have an instance that runs PHPMyAdmin.
I'm totally new in OpenCV so hopefully that's not a too stupid question. As
Totally new to Drupal so be gentle please! Let's say I have a number
I´m totally new to Powershell and wanted to write a script that deletes all
I'm totally new to jQuery and Ajax, and I'm just confused trying to work

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.