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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:50:34+00:00 2026-06-04T10:50:34+00:00

I’m having an issue having two different CorePlot graphs show up in the same

  • 0

I’m having an issue having two different CorePlot graphs show up in the same view. I’ve set up two hosting views in my view and all the referencing outlets are connected correctly. Only one of the graphs shows up correctly. Adding a quick NSLog to the numberForPlot method shows that only the first graph is being populated (graph and graphView) and not the second (trend and trendView). Here’s the code:

- (void) graphSetup {
    CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];

    graph = (CPTXYGraph *)[theme newGraph]; 

    graphView.hostedGraph = graph;
    graphView.allowPinchScaling = YES;

    graph.paddingLeft = -5;
    graph.paddingTop = 0;
    graph.paddingRight = -5;
    graph.paddingBottom = -5;
    graph.fill = nil;
    graph.plotAreaFrame.fill = nil;
    int a = 0;
    for (int i = 0; i < [romAveragesArray count]; i++) {
        if ([romAveragesArray objectAtIndex:i] != NULL)
            a++;
    }

    int localMax = 0;
    int localMin = 0;

    for (int a = 0; a < [romAveragesArray count]; a++) {
        if ([[romAveragesArray objectAtIndex:a] getValue] > localMax)
            localMax = [[romAveragesArray objectAtIndex:a] getValue];
        else if ([[romAveragesArray objectAtIndex:a] getValue] < localMin)
            localMin = [[romAveragesArray objectAtIndex:a] getValue];
    }

    for (int a = 0; a < [obaAveragesArray count]; a++) {
        if ([[obaAveragesArray objectAtIndex:a] getValue] > localMax)
            localMax = [[obaAveragesArray objectAtIndex:a] getValue];
        else if ([[obaAveragesArray objectAtIndex:a] getValue] < localMin)
            localMin = [[obaAveragesArray objectAtIndex:a] getValue];

    }


    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0)
                                                    length:CPTDecimalFromInt(145)];
    NSLog(@"%d",a);
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0)
                                                    length:CPTDecimalFromInt(localMax+15)];




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

    CPTXYAxis *x = axisSet.xAxis;
    x.majorIntervalLength = CPTDecimalFromFloat(10);
    x.minorTicksPerInterval = 2;
    x.borderWidth = 0;
    x.labelExclusionRanges = [NSArray arrayWithObjects:
                              [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-100) 
                                                           length:CPTDecimalFromFloat(300)], 
                              nil];;

    CPTXYAxis *y = axisSet.yAxis;
    y.majorIntervalLength = CPTDecimalFromFloat(10);
    y.minorTicksPerInterval = 1;
    y.labelExclusionRanges = [NSArray arrayWithObjects:
                              [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-100) 
                                                           length:CPTDecimalFromFloat(300)], 
                              nil];





    CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init];
    dataSourceLinePlot.identifier = @"Obama";
    dataSourceLinePlot.dataSource = self;
    CPTMutableLineStyle *style = [CPTMutableLineStyle lineStyle];
    style.lineColor = [CPTColor colorWithComponentRed:0.3215686274509804 green:0.6078431372549019 blue:1.0 alpha:1.0];
    dataSourceLinePlot.dataLineStyle = style;
    [graph addPlot:dataSourceLinePlot];


    CPTScatterPlot *dataSourceLinePlot1 = [[CPTScatterPlot alloc] init];
    dataSourceLinePlot1.identifier = @"Rom";
    dataSourceLinePlot1.dataSource = self;
    CPTMutableLineStyle *style1 = [CPTMutableLineStyle lineStyle];
    style1.lineColor = [CPTColor colorWithComponentRed:0.9803921568627451 green:0.47058823529411764 blue:0.47058823529411764 alpha:1.0];
    dataSourceLinePlot1.dataLineStyle = style1;
    [graph addPlot:dataSourceLinePlot1];
     [self trendSetup];

    [self postStats];

}


- (void) trendSetup {
    CPTTheme *theme1 = [CPTTheme themeNamed:kCPTPlainWhiteTheme];

    trend = (CPTXYGraph *) [theme1 newGraph];
    trendView.allowPinchScaling = YES;
    trendView.hostedGraph = trend;

    trend.paddingLeft = -5;
    trend.paddingRight = -5;
    trend.paddingTop = 0;
    trend.paddingBottom = -5;
    trend.fill =  nil;
    trend.plotAreaFrame.fill = nil;
    int obaMax, localMax;
    for (int i = 0; i < [obaArray count]; i++)
        obaMax += [[obaArray objectAtIndex:i] getValue];

    int romMax;
    for (int i = 0; i < [romArray count]; i++)
        romMax += [[romArray objectAtIndex:i] getValue];

    if (romMax > obaMax)
        localMax = romMax;
    else
        localMax = obaMax;

    CPTXYPlotSpace *trendSpace = (CPTXYPlotSpace *)trend.defaultPlotSpace;
    trendSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(504)];
    trendSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(localMax)];

    CPTXYAxisSet *trendSet = (CPTXYAxisSet *)trend.axisSet;

    CPTXYAxis *trendX = trendSet.xAxis;
    trendX.majorIntervalLength = CPTDecimalFromInt(10);
    trendX.minorTicksPerInterval = 2;
    trendX.borderWidth  = 0;
    trendX.labelExclusionRanges = [NSArray arrayWithObjects:[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-100) length:CPTDecimalFromFloat(300)], nil];;

    CPTXYAxis *trendY = trendSet.xAxis;
    trendY.majorIntervalLength = CPTDecimalFromInt(10);
    trendY.minorTicksPerInterval = 2;
    trendY.borderWidth  = 0;
    trendY.labelExclusionRanges = [NSArray arrayWithObjects:[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-100) length:CPTDecimalFromFloat(300)], nil];;

    CPTScatterPlot *trendSourceLinePlot = [[CPTScatterPlot alloc] init];
    trendSourceLinePlot.identifier = @"Obama Trend";
    trendSourceLinePlot.dataSource = self;
    CPTMutableLineStyle *style3 = [CPTMutableLineStyle lineStyle];
    style3.lineColor = [CPTColor colorWithComponentRed:0.3215686274509804 green:0.6078431372549019 blue:1.0 alpha:1.0];
    trendSourceLinePlot.dataLineStyle = style3;
    [trend addPlot:trendSourceLinePlot];


    CPTScatterPlot *trendSourceLinePlot1 = [[CPTScatterPlot alloc] init];
    trendSourceLinePlot1.identifier = @"Rom Trend";
    trendSourceLinePlot1.dataSource = self;
    CPTMutableLineStyle *style4 = [CPTMutableLineStyle lineStyle];
    style4.lineColor = [CPTColor colorWithComponentRed:0.9803921568627451 green:0.47058823529411764 blue:0.47058823529411764 alpha:1.0];
    trendSourceLinePlot1.dataLineStyle = style4;
    [trend addPlot:trendSourceLinePlot1];

}
  • 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-04T10:50:36+00:00Added an answer on June 4, 2026 at 10:50 am

    Here is something I found not-so-right with your code, and I think this is the reason Eric asked you if both hosting views are visible.

    You are creating two CPTXYGraphs one called graph another called trend. I don’t know how you set up the Views in Interface Builder, but I would NOT create two CPTXYGraphs. I would add trendSourceLinePlot & trendSourceLinePlot1 to either trend or graph.

    I think, what you need to do is to present them in the same CPTXYGraph. So, here is my suggestion…

    1. Remove the following lines in trentSetup

      CPTTheme *theme1 = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
      trend = (CPTXYGraph *) [theme1 newGraph];
      trendView.allowPinchScaling = YES;
      trendView.hostedGraph = trend;
      trend.paddingLeft = -5;
      trend.paddingRight = -5;
      trend.paddingTop = 0;
      trend.paddingBottom = -5;
      trend.fill =  nil;
      trend.plotAreaFrame.fill = nil;
      
    2. Replace ONLY the following lines

      [trend addPlot:trendSourceLinePlot];
      [trend addPlot:trendSourceLinePlot1];
      

      respectively with

      [graph addPlot:trendSourceLinePlot];
      [graph addPlot:trendSourceLinePlot1];
      

    It also should speed up the loading process.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.