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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:24:19+00:00 2026-05-22T14:24:19+00:00

I want to know how to create grouped bar graph? I tried but I

  • 0

I want to know how to create grouped bar graph? I tried but I got only single bar graph.

Below, is my code any one tell me what is the mistake .

Thank you

-(void)viewDidLoad {

    [super viewDidLoad];

[self generateDataSamples];

double xAxisStart = 0;
double xAxisLength = [samples count];

double yAxisStart = 0;
double yAxisLength = [[samples valueForKeyPath:@"@max.Y_VAL"] doubleValue];




    NSLog(@"xAxisLength===%f",xAxisLength);

    NSLog(@"yAxisLength===%f",yAxisLength);


CPGraphHostingView *hostingView = [[CPGraphHostingView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:hostingView];

CPXYGraph *graph = [[CPXYGraph alloc] initWithFrame:self.view.bounds];
hostingView.hostedGraph = graph;


CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(xAxisStart)
                                               length:CPDecimalFromDouble(xAxisLength+1)];

plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(yAxisStart)
                                               length:CPDecimalFromDouble(yAxisLength)];    


graph.plotAreaFrame.borderLineStyle = nil;
graph.plotAreaFrame.cornerRadius = 0.0f;

// Paddings
graph.paddingLeft = 0.0f;
graph.paddingRight = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingBottom = 0.0f;

graph.plotAreaFrame.paddingLeft = 70.0;
graph.plotAreaFrame.paddingTop = 20.0;
graph.plotAreaFrame.paddingRight = 20.0;
graph.plotAreaFrame.paddingBottom = 80.0;




CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;

CPXYAxis *y = axisSet.yAxis;

     y.majorIntervalLength = CPDecimalFromString(@"1");
     y.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
 y.title = @"Y Axis";
 y.titleOffset = 45.0f;
     y.titleLocation = CPDecimalFromFloat(3.0f);



//first bar
CPBarPlot *plot = [[CPBarPlot alloc]  initWithFrame:CGRectZero];
plot.plotRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0.0)
                                             length:CPDecimalFromDouble(xAxisLength)];

CPFill* cpFill = [[CPFill alloc] initWithColor:[CPColor greenColor]];
    plot.barOffset = CPDecimalFromFloat(0.25f);
plot.fill = cpFill;
plot.dataSource = self;
plot.identifier=@"plot1";
[graph addPlot:plot toPlotSpace:plotSpace];

//second bar

plot.plotRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(1.0)
                                             length:CPDecimalFromDouble(xAxisLength)];

CPFill* cpFill1 = [[CPFill alloc] initWithColor:[CPColor lightGrayColor]];  
plot.fill = cpFill1;
plot.dataSource = self;
plot.identifier=@"plot2";
[graph addPlot:plot toPlotSpace:plotSpace];


[graph addPlot:plot];
[plot release];
[graph release];
[hostingView release];
}
  • 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-22T14:24:19+00:00Added an answer on May 22, 2026 at 2:24 pm

    You never created a second plot object–your code just adds the same one to the graph twice. You also need to make sure to use a different barOffset for the second plot. If you’re not using garbage collection, watch your memory management. The code in your question has several memory leaks.

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

Sidebar

Related Questions

I want to know how to create a label that contains two icons, one
I want to know if I can create a WebBrowser through code in Vb.NET,
I want to know how to create a private attribute in a Javascript class.
I want to know how to create an image column in a SQL Server
This is a very newbie question. I want to know how to create a
I'm using multi-table-inheritance , and want to know how to create an inherited type
I want to know what happens when I create an instance of a ServiceHost
I want to know if PHPExcel can: Create Excel spreadsheets with embeded image. The
I want to know which FamilyName was used by Windows to create a font
I want to know what framework/Interface/API's Set is best to use to create multi-process

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.