横軸に時間、縦軸に気温、といった折れ線グラフが簡単に描ける。以下は付属のサンプルプログラムより。
予め値をセットして描く静的グラフ(Static Plots)の他、時間経過に合わせて描く動的グラフ(Dynamic Plots)も表示することができる。
静的グラフのコード例(上図の気温のグラフが該当)
// Configure the temperature plot strip (sparkline)
NSArray *array = [NSArray arrayWithObjects:[NSNumber numberWithFloat:68.1f],
[NSNumber numberWithFloat:70.2f],
[NSNumber numberWithFloat:71.3f],
[NSNumber numberWithFloat:72.4f],
[NSNumber numberWithFloat:73.5f],
[NSNumber numberWithFloat:70.6f],
nil];
tempPlotStrip.showDot = YES;
tempPlotStrip.capacity = array.count;
tempPlotStrip.data = array;
tempPlotStrip.lineColor = [UIColor darkGrayColor];
tempPlotStrip.labelFormat = @"%0.1f °F";
tempPlotStrip.label = tempPlotLabel;動的グラフのコード例(上図の緑線のグラフが該当)
// Configure the plotter strip
// ... This strip has high/low limits specified
plotStrip.lowerLimit = -1.0f;
plotStrip.upperLimit = 1.0f;
plotStrip.capacity = 300;
plotStrip.lineColor = [UIColor greenColor];
plotStrip.showDot = YES;
plotStrip.labelFormat = @"Timer-driven: (%0.02f)";
plotStrip.label = plotStripLabel;
:
// タイマーを設定(0.1秒毎)
m_timer = [[NSTimer scheduledTimerWithTimeInterval:0.100f
target:self
selector:@selector(didGetTimerEvent:)
userInfo:nil
repeats:YES] retain];
:
- (void) didGetTimerEvent:(NSTimer *)a_timer
{
// Add current slider value to plot strip
plotStrip.value = valueSlider.value;
}動的グラフも定期的に valueプロパティへ値を設定するだけで作ることができる。- - - - -
簡単に使えるので、ちょっとしたグラフが欲しい時に重宝しそう。
ライセンス:BSD



