gpt4 book ai didi

iphone - 使用 CorePlot 库绘制多个图形

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

我必须绘制多张图。我必须考虑一个 Y 值到红色、蓝色图和 Y2 轴值的绿色图。我正在使用核心平台库......我做了类似下面的事情并得到了图如下图所示。但我需要为 y 和 y2 设置不同的值。 enter image description here我不会画画...请帮助我...

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(self.xRangeMinVal) length:CPTDecimalFromInt(self.xRangeMaxVal)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(self.yRangeMinVal) length:CPTDecimalFromInt(self.yRangeMaxVal)];
//plotSpace.allowsUserInteraction = YES;
//plotSpace.delegate = self;

// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:2.0f], nil];
majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.4] colorWithAlphaComponent:0.4];
CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.4] colorWithAlphaComponent:0.1];

CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle];
textStyle.color = [CPTColor blackColor];
textStyle.fontSize = 16.0f;
textStyle.textAlignment = CPTTextAlignmentCenter;


CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 3.0;
axisLineStyle.lineCap = kCGLineCapRound;
// Axes
// Label x axis with a fixed interval policy
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPTDecimalFromString(@"2.0");
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0.0");
x.minorTicksPerInterval = 1;
x.majorGridLineStyle = majorGridLineStyle;
x.minorGridLineStyle = minorGridLineStyle;
//x.preferredNumberOfMajorTicks=;

x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
//x.title = [NSString stringWithFormat:@"goat"];
//x.titleOffset = 10.0;
//x.titleLocation = CPTDecimalFromString(@"0.0");
x.title = self.xLineTitle;
x.axisLineStyle = axisLineStyle;
x.titleTextStyle = textStyle;

CPTMutableLineStyle *dottedStyle=[CPTMutableLineStyle lineStyle];


x.minorGridLineStyle=dottedStyle;

// Label y with an automatic label policy.
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
// y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"-10.0");
y.minorTicksPerInterval = 2;
y.preferredNumberOfMajorTicks = 8;
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
//y.labelOffset = 1.0;
y.title = self.yLineTitle;
y.titleTextStyle = textStyle;
y.axisLineStyle = axisLineStyle;
y.titleRotation = M_PI * 0.5;
y.minorGridLineStyle=dottedStyle;


CPTXYPlotSpace *plotSpace1 = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
// CPTXYPlotSpace *plotSpace1 = [[[CPTXYPlotSpace alloc] init] autorelease];
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(self.xRangeMinVal) length:CPTDecimalFromInt(self.xRangeMaxVal)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(60)];
CPTXYAxis *y2 = [[[CPTXYAxis alloc] init] autorelease];
y2.coordinate = CPTCoordinateY;
y2.plotSpace = plotSpace1;
y2.majorGridLineStyle = majorGridLineStyle;
y2.minorGridLineStyle = minorGridLineStyle;
y2.orthogonalCoordinateDecimal = CPTDecimalFromDouble(self.xRangeMaxVal);
y2.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
//y2.separateLayers = NO;
y2.preferredNumberOfMajorTicks = 7;
y2.minorTicksPerInterval = 2;//
y2.tickDirection = CPTSignPositive;
y2.axisLineStyle = axisLineStyle;
//y2.majorTickLength = 6.0;
y2.majorTickLineStyle = axisLineStyle;
//y2.minorTickLength = 4.0;
y2.title = @"Y2 Axis";
//y2.titleTextStyle = axisTitleTextStyle;
y2.titleOffset = 40.0;

//graph.axisSet.axes = [NSArray arrayWithObjects:x, y, y2, nil];
self.graph.axisSet.axes = [NSArray arrayWithObjects:x, y,y2,nil];

最佳答案

抱歉,您不能在一个绘图空间中添加多个 x 或 y 轴。

所以无论您想做什么,只需在绘图中制作动态 y 轴或 x 轴即可。

只需计算 y 轴的最大值是 this,x 轴的最大值是 this。

但对于同一绘图空间,您必须只使用一个 y 轴和一个 x 轴。

关于iphone - 使用 CorePlot 库绘制多个图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10876409/

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