2012-07-12 17 views
6

Tôi đang cố gắng thiết lập hai biểu đồ tương tự như mẫu AAPlot được cung cấp với Lô cốt lõi. Về cơ bản nó bao gồm một biểu đồ chứng khoán, được hiển thị gần như chính xác và biểu đồ thứ hai (biểu đồ khối lượng), sẽ được đặt trực tiếp bên dưới biểu đồ chứng khoán. Cả hai biểu đồ phải chia sẻ cùng một trục x.Cốt lõi: Hai ô chia sẻ cùng trục x

Rất tiếc, dữ liệu của biểu đồ khối lượng không được vẽ trong ứng dụng của tôi.

Mặc dù tôi đã so sánh mã nguồn mẫu với tôi một cách mãnh liệt, nhưng tôi không tìm thấy nguồn lỗi của mình.

Bạn có thể vui lòng chỉ cho tôi đúng hướng không?

Đây là mã của tôi:

- (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]]; 
} 

Trả lời

1

Bạn không bao giờ đặt phạm vi khoảng không gian âm mưu cho không gian âm lượng âm lượng. Nó vẫn có phạm vi x và y mặc định là [0, 1].

3

gì xảy ra khi bạn chỉ cần làm [_graph addPlot: volumePlot] thay vì [_graph addPlot toPlotSpace: volumePlotSpace]?

Tôi nghĩ rằng bạn có thể đã thêm một số hạn chế bổ sung bằng cách sử dụng tất cả các không gian âm mưu khác nhau và điều đó đang giữ cho cả hai ô của bạn không hiển thị.

Tôi không hoàn toàn chắc chắn là thành thật mà nói, tôi cũng đã học Core cốt lõi, hầu hết các giải pháp tôi đưa ra là kết quả của rất nhiều trò chơi xung quanh và googling. Tôi sẽ chỉnh sửa bài đăng này nếu tôi nghĩ về điều gì đó khác.

+0

Sự cố vẫn giữ nguyên khi thay đổi dòng mã. Về cơ bản, tôi chỉ chuyển mã nguồn từ mẫu AAPlot, nhưng nó không hoạt động trong thiết lập của tôi. – AlexR

+0

Tôi biết có một số khác biệt giữa cách các lô được yêu cầu để thiết lập, nhưng bạn không khởi tạo âm lượng với các giới hạn của biểu đồ. Ngoài ra, bạn đã chạy qua trình gỡ rối, khối lượng thực của bạn có thực sự tồn tại hoặc chứa thông tin không? –

+0

Dữ liệu cho volumePlot không tồn tại, nguồn dữ liệu cung cấp dữ liệu chính xác. Tôi đã thiết lập âm mưu (trong mã của tôi: lô định giá) giống như trong mẫu Core Plot. – AlexR

Các vấn đề liên quan