gpt4 book ai didi

iphone - 核心图:ios在同一COT图中显示两个y轴以及散点图和条形图

转载 作者:行者123 更新时间:2023-12-01 18:23:05 24 4
gpt4 key购买 nike

嗨,请引导我使用核心绘图显示一条Y轴的两个Y轴(左侧和右侧)的书写方式,而且我也必须在单个CPTGraph中绘制Scaterplot和barplot。
CPTS散点图在Y轴的右侧显示-ve方向。

我的代码段

-(void)configureAxes
{
// 1 - Configure styles
CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor whiteColor];
axisTitleStyle.fontName = @"Helvetica-Bold";
axisTitleStyle.fontSize = 8.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:1];
CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
axisTextStyle.color = [CPTColor whiteColor];
axisTextStyle.fontName = @"Helvetica-Bold";
axisTextStyle.fontSize = 8.0f;
CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor whiteColor];
tickLineStyle.lineWidth = 2.0f;
CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor blackColor];
tickLineStyle.lineWidth = 1.0f;

// 2 - Get the graph's axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;

// 3 - Configure the x-axis
// axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
// axisSet.xAxis.title = @"";
// axisSet.xAxis.labelAlignment = CPTAlignmentRight;
// axisSet.xAxis.titleTextStyle = axisTitleStyle;
// axisSet.xAxis.titleOffset = 38.0f;
// axisSet.xAxis.axisLineStyle = axisLineStyle;
// axisSet.xAxis.labelTextStyle = axisTextStyle;
CGFloat dateCount = [self.arrayData count];
NSMutableSet *xLabels = [NSMutableSet setWithCapacity:dateCount];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:dateCount];
NSInteger i = 0;
for (ResolutionData *d in self.arrayData)
{
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[[d.appName componentsSeparatedByString:@"-"]objectAtIndex:0] textStyle:axisSet.xAxis.labelTextStyle];
// [label setRotation:45.0];
CGFloat location = i++;
label.tickLocation = CPTDecimalFromCGFloat(location);
label.offset = axisSet.xAxis.majorTickLength;
if (label) {
[xLabels addObject:label];
[xLocations addObject:[NSNumber numberWithFloat:location]];
}
}
axisSet.xAxis.axisLabels = xLabels;
axisSet.xAxis.majorTickLocations = xLocations;


// 4 - Configre the y-axis
CPTAxis *y = axisSet.yAxis;
y.title = @"count";
y.labelAlignment = CPTAlignmentCenter;
y.titleTextStyle = axisTitleStyle;
y.titleOffset = -40.0f;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = gridLineStyle;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelTextStyle = axisTextStyle;
y.labelOffset = 16.0f;
y.majorTickLineStyle = axisLineStyle;
// y.majorTickLength = 4.0f;
// y.minorTickLength = 2.0f;
y.tickDirection = CPTSignPositive;
NSInteger majorIncrement = 20;
NSInteger minorIncrement = 10;
CGFloat yMax = 100.0f; // should determine dynamically based on max price
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
int x =1;
for (NSInteger j = minorIncrement; j <= yMax; j += minorIncrement) {
NSUInteger mod = j % majorIncrement;
if (mod == 0) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", x] textStyle:y.labelTextStyle];
[label setAlignment:CPTAlignmentTop];
NSDecimal location = CPTDecimalFromInteger(j);x++;
label.tickLocation = location;
label.offset = -y.majorTickLength - y.labelOffset;
if (label) {
[yLabels addObject:label];
}
[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
} else {
[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];
}
}

y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;
y.minorTickLocations = yMinorLocations;
}

请帮我。

最佳答案

创建一个新的y轴对象,根据需要对其进行配置,然后将其添加到轴集中。

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

如果要为右y轴使用不同的比例,则需要另一个绘图空间。创建一个新的,进行配置,将 xRange设置为与默认绘图空间相同的 xRange,然后将其添加到图形中。确保将新的y轴的 plotSpace设置为新的绘图空间对象。
CPTXYPlotSpace *oldPlotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
CPTXYPlotSpace *newPlotSpace = [[[CPTXYPlotSpace alloc] init] autorelease];
newPlotSpace.xRange = oldPlotSpace.xRange;
newPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:/* location */
length:/* length */];
[graph addPlotSpace:linearPlotSpace];

有关示例代码,请参见Plot Gallery示例应用程序中的“Axis Demo”和“Plot Space Demo”。

关于iphone - 核心图:ios在同一COT图中显示两个y轴以及散点图和条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16101397/

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