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]];
}
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
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? –
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