【发布时间】:2019-11-21 11:31:57
【问题描述】:
如何在图中的数据点之间实现自定义空间,如下图所示,使用Objective c
CGRect bounds = self.graphView.bounds;
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:bounds];
self.graphView.hostedGraph = graph;
// graph.plotAreaFrame.paddingTop += 25.0;
graph.plotAreaFrame.paddingLeft += 55.0;
graph.plotAreaFrame.paddingBottom += 70.0;
graph.plotAreaFrame.paddingRight += 20.0;
// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.lineColor = self.line1Color;
//[[CPTColor colorWithGenericGray:0.2] colorWithAlphaComponent:0.75];
CPTLineCap *lineCap = [CPTLineCap sweptArrowPlotLineCap];
lineCap.size = CGSizeMake(15.0, 15.0);
// Axes
// Label x axis with a fixed interval policy
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPTDecimalFromInt(1);
x.labelingOrigin = @(0).decimalValue;
int i = 0;
NSMutableArray *customLabels = [NSMutableArray new];
NSMutableArray *titleLocations = [NSMutableArray new];
for (NSMutableDictionary *v in self.values)
{
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[[v valueForKey:@"x"] toDDMMYYYYString] textStyle:x.labelTextStyle];
newLabel.tickLocation = [[NSNumber numberWithInt:i] decimalValue];
newLabel.offset = x.labelOffset + x.majorTickLength;
newLabel.rotation = M_PI/2.0f;
[customLabels addObject:newLabel];
[titleLocations addObject:[NSNumber numberWithInt:i ]];
i++;
}
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.majorTickLocations = [NSSet setWithArray:titleLocations];
x.axisLabels = [NSSet setWithArray:customLabels];
x.majorGridLineStyle = majorGridLineStyle;
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
x.labelingOrigin = @(0).decimalValue;
x.orthogonalCoordinateDecimal = [NSDecimalNumber zero].decimalValue;
lineCap.lineStyle = x.axisLineStyle;
lineCap.fill = [CPTFill fillWithColor:lineCap.lineStyle.lineColor];
// Label y with an automatic label policy.
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.majorGridLineStyle = majorGridLineStyle;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
y.labelOffset = 10.0;
y.minorTicksPerInterval = 0;`
我已经给出了以下 xrange 和 yrange
if(self.values.count>5){
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(self.pt) length:CPTDecimalFromFloat( MAX(self.values.count, 6))];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(min) length:CPTDecimalFromFloat(max)];
}else{
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(self.pt) length:CPTDecimalFromFloat( MIN(self.values.count, 3))];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(min) length:CPTDecimalFromFloat(max)];
}
【问题讨论】:
-
显示你的代码,你在哪里计算 xAxis
-
嗨,我可以在数据点之间以相等的距离进行绘图,coreplot 中的任何方法都可以在两个数据点之间有自定义间隙/空间?
标签: objective-c core-plot