作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Core Plot 显示一个简单的散点图,但由于某种原因没有显示任何线条。我的委托(delegate)方法正在被调用(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,并且我比较了我的代码,我认为我没有遗漏任何重要的东西,但唉,我似乎.
最佳答案
绘图的绘图空间 (extendedPlotSpace
) 为 nil
,直到将绘图添加到图形中。要么将绘图空间设置移动到绘图成为图形的一部分之后,要么改用 graph.defaultPlotSpace
。
关于ios - 核心图不显示散点图线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17952133/
我是一名优秀的程序员,十分优秀!