2012-07-12 16 views
6

コアプロットで提供されるAAPlotサンプルに似た2つのチャートを設定しようとしています。 基本的には、ほぼ正確に表示される株価チャートと株価チャートの直下に配置される第2のチャート(ボリュームチャート)で構成されます。どちらのチャートも同じx軸を共有する必要があります。コアプロット:同じx軸を共有する2つのプロット

残念ながら、ボリュームチャートのデータは私のアプリにプロットされていません。

サンプルソースコードと私とを強く比較しても、エラーの原因は見つかりません。

私に正しい方向を教えてください。

これは私のコードです:代わりに[addPlot toPlotSpace _graph:volumePlotSpace]:あなただけの[volumePlot _graphのaddPlot]を実行するとどうなる

- (void)configureChart 
{ 
    self.graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds]; 
    self.hostView.hostedGraph = self.graph; 
    self.graph.paddingLeft = 0.0f; 
    self.graph.paddingTop = 0.0f; 
    self.graph.paddingRight = 0.0f; 
    self.graph.paddingBottom = 0.0f; 
    self.graph.axisSet = nil; 

    // 2 - Set up text style 
    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; 
    textStyle.color = [CPTColor grayColor]; 
    textStyle.fontName = @"Helvetica-Bold"; 
    textStyle.fontSize = 16.0f; 

    // 3 - Configure title 
    NSString *title = self.issue.company.companyName; 
    _graph.title = title;  
    _graph.titleTextStyle = textStyle; 
    _graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;  
    _graph.titleDisplacement = CGPointMake(0.0f, -12.0f);  

    // 4 - Set theme 
    [self.graph applyTheme:[CPTTheme themeNamed:kCPTStocksTheme]]; 

    _graph.plotAreaFrame.cornerRadius = 0.0f; 
    CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle]; 
    borderLineStyle.lineColor   = [CPTColor whiteColor]; 
    borderLineStyle.lineWidth   = 2.0f; 
    _graph.plotAreaFrame.borderLineStyle = borderLineStyle; 


    // Axes 
    CPTXYAxisSet *xyAxisSet  = (id)self.graph.axisSet; 
    CPTXYAxis *xAxis    = xyAxisSet.xAxis; 
    CPTMutableLineStyle *lineStyle = [xAxis.axisLineStyle mutableCopy]; 
    lineStyle.lineCap = kCGLineCapButt; 
    xAxis.axisLineStyle = lineStyle; 
    xAxis.labelingPolicy = CPTAxisLabelingPolicyNone; 

    CPTXYAxis *yAxis = xyAxisSet.yAxis; 
    yAxis.axisLineStyle = nil; 

    // OHLC plot 
    CPTMutableLineStyle *whiteLineStyle = [CPTMutableLineStyle lineStyle]; 
    whiteLineStyle.lineColor = [CPTColor whiteColor]; 
    whiteLineStyle.lineWidth = 1.0f; 
    CPTTradingRangePlot *ohlcPlot = [[CPTTradingRangePlot alloc] initWithFrame:self.graph.bounds]; 
    ohlcPlot.identifier = @"OHLC"; 
    ohlcPlot.lineStyle = whiteLineStyle; 
    CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle]; 
    whiteTextStyle.color = [CPTColor whiteColor]; 
    whiteTextStyle.fontSize = 8.0; 
    ohlcPlot.labelTextStyle = whiteTextStyle; 
    ohlcPlot.labelOffset = 5.0; 
    ohlcPlot.stickLength = 2.0f; 
    ohlcPlot.dataSource  = self; 
    ohlcPlot.plotStyle  = CPTTradingRangePlotStyleOHLC; 
    [self.graph addPlot:ohlcPlot]; 

    // Add volume plot space 
    CPTXYPlotSpace *volumePlotSpace = [[CPTXYPlotSpace alloc] init]; 
    volumePlotSpace.identifier = @"Volume"; 
    [_graph addPlotSpace:volumePlotSpace]; 

    CPTBarPlot *volumePlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor whiteColor] horizontalBars:NO]; 
    volumePlot.dataSource = self; 

    lineStyle   = [volumePlot.lineStyle mutableCopy]; 
    lineStyle.lineColor = [CPTColor whiteColor]; 
    volumePlot.lineStyle = lineStyle; 

    volumePlot.fill  = nil; 
    volumePlot.barWidth = CPTDecimalFromFloat(1.0f); 
    volumePlot.identifier = @"Volume Plot"; 
    [_graph addPlot:volumePlot toPlotSpace:volumePlotSpace]; 


    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) self.graph.defaultPlotSpace; 
    [plotSpace scaleToFitPlots:[self.graph allPlots]]; 
} 

答えて

1

ボリュームプロット空間のプロット空間範囲を決して設定しません。それでも、デフォルトのxとyの範囲は[0、1]です。

3

何?

私は、これらのさまざまなプロットスペースをすべて使用して余分な拘束を追加した可能性があり、両方のプロットが表示されないと考えています。

正直言って私は完全にはわかりませんが、私はちょうどコアプロットも学びました。私が出てきた解決策の多くは、周りを遊んで、グーグルで遊んだ結果です。私は何か他のことを考えるなら、この投稿を編集します。

+0

コード行を変更しても問題は変わりません。基本的に、私はAAPlotサンプルからソースコードを移植しましたが、私のセットアップでは機能しません。 – AlexR

+0

プロットの設定方法にはいくつかの違いがありますが、ボリュームのプロットをグラフの境界で初期化しないでください。また、デバッガを実行したか、volumePlotが実際に存在するのか、情報が含まれていますか? –

+0

volumePlotのデータは存在し、データソースは正しいデータを配信します。 Core Plotサンプルと同じ方法でボリューム・プロット(私のコード:評価プロット)を設定しました。 – AlexR