私はcoreplotと一緒に働いています - そしてこれまでこれを稼働させていました。今私は奇妙な問題につまずいた。coreplot - 常に同じプロット
私は=私はcoreplotの重要な機能やコンセプトを逃したことを恐れる)
実装イム:
numberofRecords
doubleForPlot
と何度も(特にdoubleForPlot)をデバッグしていますdoubleforplotが実際に指定されたインデックスに対して正しいdoubleを返すことを100%確信しています。
しかし、示されたプロットは、であり、常にである。私はライン(質問の下部にスクリーンショット)を取得します。
私が試した: - :空のプロット デバッグ doubleForPlotをそれが右の数値を返します 異なるデータにを私は定数線路、結果を見て期待し、常に同じ番号を返してみました。 異なるデータ私はいくつかの他の値(定数ではない)を返そうとしましたが、表示されたスクリーンショットをもう一度表示します。ここ
は私のコードは次のとおりです。
IBAction - データinizalisationを呼び出し、graphview
-(IBAction)displayDayBalanceGraph:(id)sender{
if (hasSubView) {
//[[expenseTable subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
[self updateView];
NSLog(@"%@",expenseTable.subviews);
}
else{
[self initializeMonthArray];
CPTGraphHostingView *host = [self buildGraphView];
[expenseTable addSubview:host];
graph = [[CPTXYGraph alloc ]initWithFrame:host.frame];
[graph setDelegate:self];
// CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
// [graph applyTheme:theme];
host.hostedGraph = graph;
CPTScatterPlot *plot = [[CPTScatterPlot alloc]init ];
plot.dataSource = self;
[plot setIdentifier:@"balanceChart"];
[plot setTitle:@"Balance History"];
[graph addPlot:plot];
hasSubView = !hasSubView;
}
}
ビューの作成ビルド - 右のサイズ
-(CPTGraphHostingView *)buildGraphView{
CPTGraphHostingView *view = [[CPTGraphHostingView alloc]initWithFrame:CGRectMake(0, 0, 312, 220)];
[view setBackgroundColor:[self grayColor]];
return view;
}
とホスティングビューを初期化 データ初期化は - インデックス
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{
if (fieldEnum == 0) {
NSLog(@"Axis: %d and Value: %d",fieldEnum, index+1);
return (double)(index+1);
}
if (fieldEnum == 1) {
int dayInt = [dataHandler getDayNumber:[NSDate date]].intValue;
double total = 0;
for (Expense *exp in [allMonthExpenses objectAtIndex:index]) {
total = total + exp.value.doubleValue;
}
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:(-(dayInt-(int)index-1)*(60*60*24))];
double budgetValue = [dataHandler getSpecificBudgetForDate:[NSDate dateWithTimeIntervalSinceNow:(-(dayInt-(int)index-1)*(60*60*24))] ];
total = budgetValue+total;
NSLog(@"\n Axis:%d \n Record for Day: %@ \n IndexForPlot: %d \n Value: %.2f \n",fieldEnum, date,index,total);
return total;
}
else
return 0;
}
numberOfRecordsのための右のダブルを返します - - IBActionはグラフ
-(void)initializeMonthArray{
[dataHandler updateData];
if (!allMonthExpenses) {
allMonthExpenses = [[NSMutableArray alloc]initWithCapacity:31];
}
for (NSMutableArray *temp in allMonthExpenses) {
[temp removeAllObjects];
}
[allMonthExpenses removeAllObjects];
for (int j = 0; j < 31; j++) { //fill with 31 empty mutuable arrays
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
[allMonthExpenses addObject:tempArray];
}
for (Expense *exp in dataHandler.allMonthExpenses) {
if (exp.expenseType.boolValue == 0) {
[[allMonthExpenses objectAtIndex:(exp.day.intValue-1)]addObject:exp];
}
}
}
doubleForPlotに表示するようにヒットしたときに呼び出されるエントリ
の適切な量を返します-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{
return [dataHandler getDayNumber:[NSDate date]].intValue;
}
screenshot - に関係なく、私が入力した内容のデータに示されていないプロット
LOG - このログは、正しい結果が返されることを証明終わりdoubleforplot方法で作成されます。
NSLog(@"\n Record for Day: %@ \n IndexForPlot: %d \n Value: %.2f \n",date,index,total);
アウト:
2012-03-20 10:29:55.834 DailyBudget[9493:fb03]
Record for Day: 2012-03-01 09:29:55 +0000
IndexForPlot: 0
Value: 34.35
2012-03-20 10:29:55.841 DailyBudget[9493:fb03]
Record for Day: 2012-03-02 09:29:55 +0000
IndexForPlot: 1
Value: 8.35
2012-03-20 10:29:55.848 DailyBudget[9493:fb03]
Record for Day: 2012-03-03 09:29:55 +0000
IndexForPlot: 2
Value: 35.83
2012-03-20 10:29:55.856 DailyBudget[9493:fb03]
Record for Day: 2012-03-04 09:29:55 +0000
IndexForPlot: 3
Value: -14.89
2012-03-20 10:29:55.863 DailyBudget[9493:fb03]
Record for Day: 2012-03-05 09:29:55 +0000
IndexForPlot: 4
Value: 36.56
2012-03-20 10:29:55.869 DailyBudget[9493:fb03]
Record for Day: 2012-03-06 09:29:55 +0000
IndexForPlot: 5
Value: 8.96
.... sparing you a lot of other log except the last.
2012-03-20 10:29:55.980 DailyBudget[9493:fb03]
Record for Day: 2012-03-20 09:29:55 +0000
IndexForPlot: 19
Value: 14.33
こんにちは - ありがとう!これはなぜそれが直線x = yを示すのかを説明する。私はそれを変更しました(問題の新しいコードを見てください) - しかし、今私は空のプロットを得る(スクリーンショット参照)。そうではありません; –
グラフの範囲を正しく設定していますか? – Neo
aaand - それはそれでした=) –