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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:40:15+00:00 2026-05-24T02:40:15+00:00

There are a lot of question about graph with gradient here but I can’t

  • 0

There are a lot of question about graph with gradient here but I can’t find solution for my case. How to draw multiple pathes right? I wanna something like this – Gradient effect for Line Graph in iPhone

I draw gradient fine, but i need put graph line above gradient. I create another path for that and draw it later after drawing gradient, but it didn’t appear. I don’t draw original path because it’s closed path, but I want open draw line strokepath.

// create the path
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0.0+offset, self.frame.size.height-0.0);

CGMutablePathRef strokePath = CGPathCreateMutable();

NSArray *graphValues = [delegate getDataForGraph];

float mulitplX = (self.frame.size.width - offset) / (float) ([graphValues count]-1);

float lastx;

for (int i = 0; i < [graphValues count]; i++) {
    CGPoint val = [[graphValues objectAtIndex: i] CGPointValue];
    lastx=val.x;
    CGPathAddLineToPoint(path, NULL, (val.x*mulitplX)+offset, self.frame.size.height-val.y);

    if (!i) {
        CGPathAddLineToPoint(strokePath, NULL,(val.x*mulitplX)+offset, self.frame.size.height-val.y);
    } else {
        CGPathMoveToPoint(strokePath, NULL, (val.x*mulitplX)+offset, self.frame.size.height-val.y);
    }            
}

//close path for gradient
CGPathAddLineToPoint(path, NULL, lastx*mulitplX+offset, self.frame.size.height-0.0);
CGPathAddLineToPoint(path, NULL, 0.0+offset, self.frame.size.height-0.0);

// setup the gradient
CGFloat locations[2] = { 1.0, 0.0 };
CGFloat components[8] = {
    0.95, 0.30, 0.30, 0.0,  // Start color
    0.93, 0.94, 0.30, 1.0   // End color
};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradientFill = CGGradientCreateWithColorComponents (colorSpace, components, locations, 2);

// setup gradient points
CGRect pathRect = CGPathGetBoundingBox(path);
CGPoint myStartPoint, myEndPoint;
myStartPoint.x = CGRectGetMinX(pathRect);
myStartPoint.y = CGRectGetMinY(pathRect);
myEndPoint.x = CGRectGetMinX(pathRect);
myEndPoint.y = CGRectGetMaxY(pathRect);

// draw the gradient
CGContextAddPath(context, path);
CGContextSaveGState(context);
CGContextClip(context);
CGContextDrawLinearGradient (context, gradientFill, myStartPoint, myEndPoint, 0);
CGContextRestoreGState(context);

// draw the graph - problem here
CGContextBeginPath(context);
CGContextAddPath(context, strokePath);
[[UIColor whiteColor] setStroke];
CGContextSetLineWidth(context, 2.0);
CGContextStrokePath(context);

// cleanup
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradientFill);
CGPathRelease(path);
CGPathRelease(strokePath);
  • 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-24T02:40:16+00:00Added an answer on May 24, 2026 at 2:40 am

    There’s a WWDC 2011 session by the guy who wrote the built-in Stocks app, whose graphs seem similar to what you’re trying to do. He basically spends the whole hour showing how it’s done. I forget the exact session title, maybe something with Core Animation?

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

Sidebar

Related Questions

There's a lot of questions about bookmarks but none of them answers my question:
Now i know there have been a lot of question about this, but i
There are a lot of questions about didRegisterForRemoteNotificationsWithDeviceToken but they all sidestep a very
I know there's a lot of questions about this but I've been struggling with
ok, I know there are a lot of questions here about this, that are
There are a lot of questions on Stackoverflow about curl but I could not
Sorry for this question. There is a lot of information but unfortunately I haven't
I ask a question about using XPath function there But I meet a problem
I saw a lot of examples of CopyStream implementation but I have question about
Somebody has already asked my question about detecting SVG support in browsers but there

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.