我試圖設置兩個圖表,類似於Core繪圖提供的AAPlot示例。 它基本上包含一個幾乎正確顯示的股票圖表和一個應放置在股票圖表正下方的第二個圖表(交易量圖表)。兩個圖表應該共享相同的x軸。核心繪圖:共享相同x軸的兩個繪圖
不幸的是,體積圖的數據沒有被繪製在我的應用程序中。
儘管我強烈地將示例源代碼與我的比較,但我沒有發現我的錯誤的來源。
請你指點我正確的方向?
這是我的代碼:代替:當你只是做[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]];
}
更改代碼行時問題仍然存在。基本上,我只是從AAPlot示例中移植源代碼,但它在我的設置中不起作用。 – AlexR 2012-07-12 19:51:31
我知道如何設置繪圖有一些區別,但是您不用圖的邊界初始化容積圖。另外,你是否運行過調試器,你的volumePlot是否存在或包含信息? – 2012-07-12 19:59:13
volumePlot的數據確實存在,數據源提供正確的數據。我已經在Core Plot示例中設置了體積圖(在我的代碼:評估圖中)。 – AlexR 2012-07-12 20:20:30