私は最初のiPadプロジェクトでCore Plot 0.9を使用しています。私は水平の棒グラフを作成し、各バーの中心に合わせて左にUIButtonsを作成する必要があります。棒ごとに1つのボタンがあります。付属のscreenshotを参照してください。UIButtonsを水平なCore Plotのバープロットに合わせるCPTBarPlot
私のセットアップは非常に簡単です:
私はコンテナとして機能するカスタムUIViewのサブクラスを持っています。 その中に、私は2つのサブビューがあります:CPTGraphHostingViewと私のUIButtonsを含むためのUIView。 CPTGraphHostingViewでCPTXYGraphをホストし、いくつかのパディング値を割り当てます。私のカスタムクラスで
、私は、DataSourceが設定された後にボタンを作成します方法があります:私は気づい...
for (int i = 0; i < nbRecords; i++) {
// grab the bar location and create a plot point for it
NSNumber* loc = [dataSource numberForPlot:plot field:CPTBarPlotFieldBarLocation recordIndex:i];
double plotPoint[2] = {0, [loc doubleValue]};
// Convert the plot point to plot area space coordinates (I guess ;))
CGPoint viewPoint = [graph.defaultPlotSpace plotAreaViewPointForDoublePrecisionPlotPoint:plotPoint];
// Convert the view point to the button container layer coordinate system
CGPoint p = [graph convertPoint:viewPoint fromLayer:graph.plotAreaFrame.plotArea];
// Create the button
CGRect rect = CGRectMake(0, p.y - 11, 100, 22);
UIButton *btn = [[UIButton alloc] initWithFrame:rect];
[btn setTitle:@"test" forState:UIControlStateNormal];
[buttonView addSubview:btn];
[self addSubview:btn];
[array addObject:btn];
[btn release];
}
ボタンが作成されますが、アライメントが良くないのであればIすべてのグラフのパディングを0に設定すると、ボタンは整列します(もちろん、パディングが必要です)。
ポイントの変換に何かまたはステップがありませんか? plotAreaPointの座標を他のUIViewに変換する方法についてちょっと混乱しています...!