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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:36:16+00:00 2026-05-26T06:36:16+00:00

In my iPhone app, I have a view with two separate bar plots. Each

  • 0

In my iPhone app, I have a view with two separate bar plots. Each plot has a different number of data elements. I would like to label each bar in each plot with the appropriate data, but apparently the “dataLabelForPlot” method only allows one instance of “CPTTextLayer.” I would like to have the CPTTextLayer be a function of the plot and its data.

The plots have separate identifiers: “Bar Plot 1” and “Bar Plot 2.” I can use the conditional if statement in the “numberOfRecordsForPlot” and “numberForPlot” methods, but it fails in the “dataLabelForPlot” method with errors saying that “label” is an unused variable. Seem very odd to me seeing that it is defined in the conditional statements.

My code looks like this:

#pragma mark Plot Data Source Methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
if (plot.identifier == @"Bar Plot 1") {
    return 5; }
  else { return 4; }
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
    NSDecimalNumber *num = nil;
if (plot.identifier == @"Bar Plot 1") {
    switch ( fieldEnum ) {
        case CPTBarPlotFieldBarLocation:
            num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index];
            break;
        case CPTBarPlotFieldBarTip:               
            num = (NSDecimalNumber *)[dataTemp1 objectAtIndex:index];                
            break;
    }
}
else {
    switch ( fieldEnum ) {
        case CPTBarPlotFieldBarLocation:
            num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index];
            break;
        case CPTBarPlotFieldBarTip:                
            num = (NSDecimalNumber *)[dataTemp2 objectAtIndex:index];
            break;
    }
}
    return num;
}

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
  if (plot.identifier == @"Bar Plot 1") {
    CPTTextLayer *label = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", [dataTemp1 objectAtIndex:index]]]; 
    }
  else { CPTTextLayer *label = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", [dataTemp2 objectAtIndex:index]]]; }    
    CPTMutableTextStyle *textStyle = [label.textStyle mutableCopy];

    textStyle.color = [CPTColor redColor];
    label.textStyle = textStyle;
    [textStyle release];
return [label autorelease];
}
  • 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-05-26T06:36:16+00:00Added an answer on May 26, 2026 at 6:36 am

    You’ve declared label inside each of the if and else blocks, making it local to those blocks. Move the variable declaration before the if statement.

    CPTTextLayer *label;
    if (plot.identifier == @"Bar Plot 1") {
        label = ...;
    }
    else {
        label = ...;
    }
    return [label autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone app, it has two separate MKMapView components in different views,
I have an iPhone app that shows a simple view (View 1) that has
In my iPhone Core Data app I have it configured in a master-detail view
I have an iPhone app that hides the status bar. However, my main view
Im doing an Iphone app with a UIPickerView. The picker view has two columns
I'm currently developing an iPhone app where I have two UITextField's in one View
In my iPhone app, In Table view I have Two labels in one cell..
I have an iphone app. The view is consists of two children: a tableview
In my iPhone app, I have a view controller with two views (essentially, a
In the iPhone app I'm currently working on, I'd like two view controllers (I'll

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.