昨日からこれについて頭を悩ませていて、うまくいきません!私が得るのは、単純な x 軸の線、y 軸の線 (目盛りやラベルでさえありません!)、およびチャートのタイトルだけです! 助けてください!とてもシンプルに見えますが、とらえどころのないものです。
サーバーのメモリ使用量の最後の 5 つの値をプロットしています。値はおよそ 1 分ごとです (2 分ごとの場合もあります)。たとえば、表示したい最後の 5 つの値のセットは次のようになります。
日付 (対) メモリ使用量 (バイト)
2013-05-02 11:50:33 +0000 - 157888512.000000
2013-05-02 11:51:33 +0000 - 157839360.000000
2013-05-02 11:52:14 +0000 - 157888512.000000
2013-05-02 11:56:36 +0000 - 157863936.000000
2013-05-02 11:57:48 +0000 - 157888512.000000
このグラフは毎分更新します。
「numberForPlot」、「numberOfRecordsForPlot」が呼び出されたようですが、グラフにプロットが表示されません。
私のグラフはこのメソッドで初期化されます:
-(void) initializeGraph {
NSLog(@"View_Visualizer.initializeGraph");
if ((self.graph == nil) || (self.graph == NULL)) {
self.graphHostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
self.graph = [[CPTXYGraph alloc] initWithFrame:self.graphHostView.bounds];
graph.paddingLeft = 10.0;
graph.paddingRight = 10.0;
graph.paddingTop = 10.0;
graph.paddingBottom = 10.0;
graph.title = @"Processor Usage";
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
NSTimeInterval xLow = 0.0f;
NSTimeInterval oneMin = 60.0f;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xLow)
length:CPTDecimalFromFloat(oneMin*6.0)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
length:CPTDecimalFromFloat(6)];
// plotting style is set to line plots
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;
NSTimeInterval oneMin = 60.0f;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.graph.axisSet;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(oneMin);
axisSet.xAxis.minorTicksPerInterval = 0;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.majorTickLength = 7.0f;
//axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(oneMin);
//axisSet.xAxis.majorTickLineStyle = lineStyle;
//axisSet.xAxis.minorTickLineStyle = lineStyle;
//axisSet.xAxis.axisLineStyle = lineStyle;
//axisSet.xAxis.minorTickLength = 5.0f;
//axisSet.xAxis.majorTickLength = 5.0f;
//axisSet.xAxis.labelOffset = 3.0f;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// Example date format : 2013-05-02 11:23:16 +0000
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];
//dateFormatter.dateStyle = kCFDateFormatterShortStyle;
//dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = [NSDate dateWithTimeIntervalSince1970:([[NSDate date] timeIntervalSince1970] - (6*oneMin))];
axisSet.xAxis.labelFormatter = timeFormatter;
//axisSet.yAxis.majorIntervalLength = [NSDecimal decimalNumberWithString:@"5"];
//axisSet.yAxis.minorTicksPerInterval = 4;
//axisSet.yAxis.majorTickLineStyle = lineStyle;
//axisSet.yAxis.minorTickLineStyle = lineStyle;
//axisSet.yAxis.axisLineStyle = lineStyle;
//axisSet.yAxis.minorTickLength = 5.0f;
//axisSet.yAxis.majorTickLength = 5.0f;
//axisSet.yAxis.labelOffset = 3.0f;
CPTScatterPlot *xSquaredPlot = [[CPTScatterPlot alloc]
initWithFrame:self.graph.bounds];
xSquaredPlot.identifier = @"X Squared Plot";
CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
xSquaredPlot.dataLineStyle = dataLineStyle;
xSquaredPlot.dataSource = self;
[self.graph addPlot:xSquaredPlot];
self.graphHostView.allowPinchScaling = NO;
self.graphHostView.hostedGraph = self.graph;
[self.view addSubview:self.graphHostView];
}
}
#pragma mark - CPTPlotDataSource methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
return [dictHealth count];
}
-(NSNumber *) numberForPlot:(CPTPlot *)plot
field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index {
Health_MemUse *healthData = (Health_MemUse *) [dictHealth objectForKey: [self.arrayHealthKeys objectAtIndex:index]];
if ( fieldEnum == CPTScatterPlotFieldX ) {
return [NSDecimalNumber numberWithFloat:[healthData.currDate timeIntervalSince1970]];
/*
return [NSNumber numberWithDouble:([healthData.currDate timeIntervalSince1970] + [[NSTimeZone localTimeZone] secondsFromGMT])];
*/
} else {
NSLog(@"Plot memuse %f on date %@ for index %d",
healthData.memUse, healthData.currDate, index);
return [NSNumber numberWithFloat:(healthData.memUse/(1024*1024*1024))]; // convert bytes to GB
}
}
助けてください!軸の範囲を設定する際にほとんど間違っている可能性があることに気付きましたが、グーグル、スタックオーバーフローを試し、いくつかのバリエーションを試しましたが、すべて無駄でした。