グラフのタイトルを描く
// Graph title graph.title = @"Graph Title\nBar Graph"; CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle]; textStyle.color = [CPTColor cyanColor]; textStyle.fontSize = 16.0f; textStyle.textAlignment = CPTTextAlignmentCenter; graph.titleTextStyle = textStyle; graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop; graph.titleDisplacement = CGPointMake(80.0f, -30.0f);
単純に graph.title に NSString で設定するだけ。
スタイルも CPTMutableTextStyle で色々と設定できる。
タイトルを描く位置だけど、デフォルトでは CPTRectAnchorTop でこれは中央の一番上。
今回、タイトルの文字列を \n 入れて2行にしたらタイトルが画面上部にはみ出してしまった…。
そこで、titleDisplacement を使って位置を右に 80ピクセル、下に 30ピクセル動かしている。
ちなみに、titlePlotAreaFrameAnchor には以下の値が入る。
CPTRectAnchorBottomLeft | The bottom left corner |
CPTRectAnchorBottom | The bottom center |
CPTRectAnchorBottomRight | The bottom right corner |
CPTRectAnchorLeft | The left middle |
CPTRectAnchorRight | The right middle |
CPTRectAnchorTopLeft | The top left corner |
CPTRectAnchorTop | The top center |
CPTRectAnchorTopRigh | The top right |
CPTRectAnchorCenter | The center of the rect |
というわけで、今日はここまで。
明日はグラフに値を(棒を)描いて終了!