我正在尝试使用 Core Plot 显示一个简单的散点图,但无论出于何种原因,都没有显示线条。我的委托方法被调用(numberOfRecordsForPlot:
和numberForPlot:field:recordIndex:
)。这是我为设置图表所做的工作:
CPTGraphHostingView* extendedHost = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, extendedView.frameBottom, self.view.frameWidth, roomForScrollingComponentAndGraph - extendedForecastView.frameHeight)];
[extendedHost setBackgroundColor:backgroundColor(1.f)];
[self.view addSubview:extendedHost];
CPTXYGraph* extendedGraph = [[CPTXYGraph alloc] initWithFrame:extendedHost.bounds];
extendedGraph.paddingBottom = graphPadding;
extendedGraph.paddingLeft = graphPadding;
extendedGraph.paddingRight = graphPadding;
extendedGraph.paddingTop = graphPadding;
CPTXYPlotSpace* extendedPlotSpace = (CPTXYPlotSpace*)extendedGraph.defaultPlotSpace;
extendedPlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(20)];
extendedPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(100)];
[extendedGraph applyTheme:[CPTTheme themeNamed:kCPTDarkGradientTheme]];
CPTXYAxisSet* extendedAxisSet = (CPTXYAxisSet*)extendedGraph.axisSet;
CPTXYAxis* extendedX = extendedAxisSet.xAxis;
extendedX.minorTicksPerInterval = 0;
extendedX.titleTextStyle = style;
extendedX.orthogonalCoordinateDecimal = CPTDecimalFromInt(0);
NSMutableArray* extendedMajorTicks = [[NSMutableArray alloc] init];
for(int idx = 0; idx < 14; idx++) {
[extendedMajorTicks addObject:@(idx)];
}
extendedX.majorTickLocations = [NSSet setWithArray:extendedMajorTicks];
extendedX.labelingPolicy = CPTAxisLabelingPolicyLocationsProvided;
extendedX.delegate = self;
CPTXYAxis* extendedY = extendedAxisSet.yAxis;
extendedY.preferredNumberOfMajorTicks = 4;
extendedY.minorTicksPerInterval = 1;
extendedY.labelingPolicy = CPTAxisLabelingPolicyEqualDivisions;
extendedY.titleTextStyle = style;
extendedY.orthogonalCoordinateDecimal = CPTDecimalFromInt(0);
extendedY.delegate = self;
CPTScatterPlot* extendedPlot = [[CPTScatterPlot alloc] init];
extendedPlot.delegate = self;
CPTMutableLineStyle *extendedLineStyle = [CPTMutableLineStyle lineStyle];
extendedLineStyle.lineJoin = kCGLineJoinRound;
extendedLineStyle.lineCap = kCGLineCapRound;
extendedLineStyle.miterLimit = 2.f;
extendedLineStyle.lineWidth = 2.f;
extendedLineStyle.lineColor = [CPTColor colorWithCGColor:[UIColor whiteColor].CGColor];
extendedPlot.dataLineStyle = extendedLineStyle;
extendedPlot.dataSource = self;
extendedPlot.title = @"Extended";
_extendedPlot = extendedPlot;
[extendedGraph addPlot:extendedPlot];
_extendedGraph = extendedGraph;
[extendedHost setHostedGraph:_extendedGraph];
我觉得这是我遗漏的一些小东西,因为我之前在其他项目中使用过 Core Plot,并且我比较了我的代码,我认为我没有遗漏任何重要的东西,但唉,我似乎是。