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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:00:59+00:00 2026-06-01T19:00:59+00:00

Is there a way to add an average horizontal line (or a whatever single

  • 0

Is there a way to add an average horizontal line (or a whatever single line) to a bar chart graph using core plot framework?

Thanks.

  • 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-01T19:01:00+00:00Added an answer on June 1, 2026 at 7:01 pm

    One way of doing this is by using CPTScatterPlot:

    Add Following lines to your code after you have initialized and added your bar plot(or what ever your actual data plot is) to your graph.

    // Before following code, initialize your data, actual data plot and add plot to graph
    
    CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
    CPTMutableLineStyle * lineStyle                      = [CPTMutableLineStyle lineStyle];
    lineStyle.lineWidth              = 3.f;
    lineStyle.lineColor              = [CPTColor blackColor];
    lineStyle.dashPattern            = [NSArray arrayWithObjects:[NSNumber numberWithFloat:3.0f], [NSNumber numberWithFloat:3.0f], nil];
    dataSourceLinePlot.dataLineStyle = lineStyle;
    dataSourceLinePlot.identifier    = @"horizontalLineForAverage";
    dataSourceLinePlot.dataSource    = self;
    [barChart addPlot:dataSourceLinePlot toPlotSpace:plotSpace];
    

    Then add datasource methods, in my case I have set the datasource in above code to self, so I am defining datasource methods in the same file:

    -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
    {   
    // Note this method will return number of records for both my actual plot, and for scattered plot which is used to draw horizontal average line. For latter, this will decide the horizontal length of your line
        return [myDataArray count];
    }
    
    -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
    {
        NSDecimalNumber *num = nil;
    
            // If method is called to fetch data about drawing horizontal average line, then return your generated average value.
        if( plot.identifier==@"horizontalLineForAverage")
        {
            if(fieldEnum == CPTScatterPlotFieldX )
            {
                        // this line will remain as it is
                num =(NSDecimalNumber *)[NSDecimalNumber numberWithDouble:index];
            }
            else
            {
                num = (NSDecimalNumber *) myDataAverageValue;// Here you generate average value for location of horizontal line. You should edit this line only;
            }
        }
    // handle other cases and return data for other plots       
        return num;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to add some custom font on a website without using
Is there a way to add a customize DatagridviewRow using c#? Ive made a
Is there any way to add a photo to Twitter timeline using TWRequest or
I created this regular expression to validate names: ^[a-zA-Z0-9\s\-\,]+.\*?$ Is there a way add
is there a way to add an existing classic ASP webapp into a solution
Is there a way to add assembly attributes to a Managed C++ assembly? In
Is there a way to add a resource to a ResourceDictionary from code without
Is there any way to add a field to a class at runtime (
is there a way to add the results of 2 different queries to a
Is there a way to add a Subversion repository as a Git submodule in

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.