gpt4 book ai didi

ios - 核心图不显示散点图线

转载 作者:行者123 更新时间:2023-11-29 10:56:45 26 4
gpt4 key购买 nike

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com