次のような単純な線グラフを作成したいと思います。
私はいくつかのサンプルを見つけるためにグーグルで検索しました、そして私は重すぎるように見えるCorePlotを手に入れました。以下のような線グラフの作成方法を教えてもらえますか、チュートリアルも大歓迎です。お願いします
次のような単純な線グラフを作成したいと思います。
私はいくつかのサンプルを見つけるためにグーグルで検索しました、そして私は重すぎるように見えるCorePlotを手に入れました。以下のような線グラフの作成方法を教えてもらえますか、チュートリアルも大歓迎です。お願いします
Well, first, why calling that graph simple? You can make it by drawing vertical lines along the X coordinate. You have (probably) an array with the top points (that show the weight progress), so you draw a line from a top point till the base line in a loop that will parse all your top points. Here is the code to draw a line, call it for each top point:
-(void)drawLineFromX:(CGPoint)topPoint{
UIGraphicsBeginImageContext(instanceToYourImageView.image.size);
[instanceToYourImageView.image drawInRect:CGRectMake(0, 0, instanceToYourImageView.image.size.width, instanceToYourImageView.image.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y + a_value_to_reach_the_base_line);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[instanceToYourImageView setImage:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
}
Here the CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
is black, but you can easily change it to the desired one.
Cheers!
or you can use this https://github.com/pyanfield/WSChart