2017-04-27 10 views
0

貧しい私の英語を残念に思う。私は線グラフではなく、グラフでいくつかの線を描きたいですか?

これは私の質問です。

グラフ(https://github.com/danielgindi/Charts)で線を描きたいと思います。私はラインに関する情報を持っています。例えば

@interface Line : NSObject 
@property (assign, nonatomic) float x1;//x of the first point 
@property (assign, nonatomic) float x2;//x of the second point 
@property (assign, nonatomic) float y1;//y of the first point 
@property (assign, nonatomic) float y2;//y of the second point 

-(instancetype)initWithX1:(float)x1 withY1:(float)y1 withX2:(float)x2 withY2:(float)y2; 
@end 

私はその後、私はそれを描きたい、配列に行のオブジェクトを置きます。

どうすればこの機能を実現できますか?

+0

を使用** drawInRect:**上このビュー。 – Sergey

+0

@ Sergeyあなたは私にもっと情報を提供できますか?メソッドdrawInRect:どのクラスが属していますか? –

+0

チャートデモを見ましたか? – Koen

答えて

0

私はチャートを描画するための優れた方法を見つけました。

あなたは、私はラインの色を変更した場合、私は問題を解決することができ、この Multiple Line Chart

のように、私は複数の折れ線グラフを見つけ、githubのからチャートデモをダウンロードすることができます。これは私のコードです:

私はプロジェクトを再実行して、〜! enter image description here

0

すべてのビューにはdrawRect:メソッドがあります。 新しいビューを作成し、その描画メソッドをオーバーライドするだけです。

-(void)drawRect:(CGRect)rect { 
    [super drawRect:rect]; 
} 

あなたが内部UIBezierPathを使用することができます自分自身を描画実行するには:

UIBezierPath * axis = [UIBezierPath bezierPath]; 
axis.lineWidth = 1; 
[axis moveToPoint: startOfAxis]; 
[axis addLineToPoint: endOfAxis]; 
[[UIColor blackColor] setStroke]; 
[axis stroke]; 

またはチャートビューの後に透明ビューを追加して実装しようCGContextFillRect

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSaveGState(context); 

// Colors 
CGContextSetFillColorWithColor(context, backgroundColor.CGColor); 
CGContextSetStrokeColorWithColor(context, strokeColor.CGColor); 

// Drawing 
CGContextFillRect(context, textRect); 
CGContextStrokeRect(context, textRect); 

CGContextRestoreGState(context); 
関連する問題