How to write text(using CGContextShowTextAtPoint) on graph x and y-axis intervals points?
Posted
by Rajendra Bhole
on Stack Overflow
See other posts from Stack Overflow
or by Rajendra Bhole
Published on 2010-03-31T09:05:51Z
Indexed on
2010/04/01
7:33 UTC
Read the original article
Hit count: 372
iphone
|core-graphics
I developed graph using NSObject class and using CGContext method. The following code displaying dynamically in X and Y-axis intervals,
CGContextSetRGBStrokeColor(ctx, 2.0, 2.0, 2.0, 1.0);
CGContextSetLineWidth(ctx, 2.0);
CGContextMoveToPoint(ctx, 30.0, 200.0);
CGContextAddLineToPoint(ctx, 30.0, 440.0);
for(float y = 400.0; y >= 200.0; y-=30)
{
CGContextSetRGBStrokeColor(ctx, 2.0, 2.0, 2.0, 1.0);
CGContextMoveToPoint(ctx, 28, y);
CGContextAddLineToPoint(ctx, 32, y);
CGContextStrokePath(ctx);
//CGContextClosePath(ctx);
}
CGContextMoveToPoint(ctx, 10, 420.0);
CGContextAddLineToPoint(ctx, 320, 420.0);
//CGContextAddLineToPoint(ctx, 320.0, 420.0);
//CGContextStrokePath(ctx);
for(float x = 60.0; x <= 260.0; x+=30)
{
CGContextSetRGBStrokeColor(ctx, 2.0, 2.0, 2.0, 1.0);
CGContextMoveToPoint(ctx, x, 418.0);
CGContextAddLineToPoint(ctx, x, 422.0);
CGContextStrokePath(ctx);
CGContextClosePath(ctx);
}
I want to write the dynamic text on the X and Y-axis lines near the intervals (like X-axis is denoting number of days per week and Y-axis denoting something per someting)? Thanks.
© Stack Overflow or respective owner