Я использую coreplot для построения двух графиков в одном представлении.Данные, которые наносятся на график, изменяются, когда пользователь выбирает получение различных типов данных.
Данные, которые я получаю, отображаются правильно.Однако я хотел бы изменить диапазон одной из осей Y, когда это необходимо.(Данные могут отличаться от 0 до 40 или от 0,0 до 1,0).
Как реализовать эту функцию, чтобы при отображении пользователем данных от 0,0 до 1,0 по оси Y его диапазон также изменялся на эти значения
Вот фрагмент моего кода:
- (void)renderInLayer:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme fromGraph:(int)graphNumber
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect bounds = layerHostingView.bounds;
layerHostingView.backgroundColor = [UIColor clearColor];
// Create the graph and assign the hosting view.
graph = [[CPTXYGraph alloc] initWithFrame:bounds];
layerHostingView.hostedGraph = graph;
[graph applyTheme:theme];
graph.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
graph.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
graph.plotAreaFrame.borderLineStyle = nil;
graph.plotAreaFrame.masksToBorder = NO;
// chang the chart layer orders so the axis line is on top of the bar in the chart.
NSArray *chartLayers = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:CPTGraphLayerTypePlots],
[NSNumber numberWithInt:CPTGraphLayerTypeMajorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeMinorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLabels],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisTitles],
nil];
graph.topDownLayerOrder = chartLayers;
[chartLayers release];
// Add plot space for horizontal bar charts
graph.paddingLeft = 45.0;
graph.paddingTop = 40.0;
graph.paddingRight = 45.0;
graph.paddingBottom = 60.0;
// Setup plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.delegate = self;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(28.0f)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(45)];
CPTScatterPlot *highPlot2 = [[[CPTScatterPlot alloc] init] autorelease];
highPlot2.identifier = @"Graph2";
CPTMutableLineStyle *highLineStyle2 = [[highPlot2.dataLineStyle mutableCopy] autorelease];
highLineStyle2.lineWidth = 1.f;
highLineStyle2.lineColor = [CPTColor colorWithComponentRed:0.00f green:0.00f blue:0.00f alpha:0.0f];
highPlot2.dataLineStyle = highLineStyle2;
highPlot2.dataSource = self;
CPTFill *areaFill2 = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:0.00f green:0.92f blue:0.0f alpha:0.58f]];
highPlot2.areaFill = areaFill2;
highPlot2.shadow = Shadow;
highPlot2.areaBaseValue = CPTDecimalFromString(@"0");
[graph addPlot:highPlot2];
// Setup grid line style
CPTMutableLineStyle *majorXGridLineStyle = [CPTMutableLineStyle lineStyle];
majorXGridLineStyle.lineWidth = 1.0f;
majorXGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.60f];
CPTMutableTextStyle *TextStyleBlack = [CPTMutableTextStyle textStyle];
TextStyleBlack.color = [CPTColor blackColor];
TextStyleBlack.fontSize = 15.0;
// Setup x-Axis.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.majorGridLineStyle = majorXGridLineStyle;
x.majorIntervalLength = CPTDecimalFromString(@"1");
x.minorTicksPerInterval = 1;
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
x.title = @"Days";
x.timeOffset = 30.0f;
NSArray *exclusionRanges = [NSArray arrayWithObjects:[CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(0)], nil];
x.labelExclusionRanges = exclusionRanges;
NSMutableArray *labels = [[NSMutableArray alloc] initWithCapacity:[sampleDays count]];
int idx = 0;
for (NSString *day in sampleDays)
{
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:day textStyle:x.labelTextStyle];
label.tickLocation = CPTDecimalFromInt(idx);
label.offset = 5.0f;
[labels addObject:label];
[label release];
idx++;
}
x.axisLabels = [NSSet setWithArray:labels];
[labels release];
// Setup y-Axis.
CPTMutableLineStyle *majorYGridLineStyle = [CPTMutableLineStyle lineStyle];
majorYGridLineStyle.lineWidth = 1.0f;
majorYGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.60];
CPTXYAxis *y1 = axisSet.yAxis;
y1.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"10"]decimalValue];
y1.labelShadow = Shadow;
y1.minorTicksPerInterval = 0;
y1.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
y1.labelTextStyle = TextStyleYellow;
y1.labelOffset = 15;
y1.axisLineStyle = nil;
NSArray *yExlusionRanges = [NSArray arrayWithObjects:
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(0)],
nil];
y1.labelExclusionRanges = yExlusionRanges;
//setup second y axis
CPTXYAxis *y2 = [[(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero] autorelease];
y2.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y2.orthogonalCoordinateDecimal = CPTDecimalFromString(@"27");
y2.minorTicksPerInterval = 0;
y2.preferredNumberOfMajorTicks = 4;
y2.majorGridLineStyle = majorYGridLineStyle;
y2.labelOffset = - 40.0;
y2.coordinate = CPTCoordinateY;
y2.plotSpace = graph.defaultPlotSpace;
y2.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"10"]decimalValue];
y2.minorTickLineStyle = nil;
y2.axisLineStyle = nil;
//add all axis to the graph
graph.axisSet.axes = [NSArray arrayWithObjects:x, y1, y2,nil];
// Create a high plot area
CPTScatterPlot *highPlot = [[[CPTScatterPlot alloc] init] autorelease];
highPlot.identifier = kHighPlot;
CPTMutableLineStyle *highLineStyle = [[highPlot.dataLineStyle mutableCopy] autorelease];
highLineStyle.lineWidth = 1.f;
highLineStyle.lineColor = [CPTColor colorWithComponentRed:0.00f green:0.00f blue:0.00f alpha:0.0f];
highPlot.dataLineStyle = highLineStyle;
highPlot.dataSource = self;
//fillcolor
CPTFill *areaFill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:1.00f green:0.97f blue:0.0f alpha:0.41f]];
highPlot.areaFill = areaFill;
highPlot.shadow = Shadow;
highPlot.areaBaseValue = CPTDecimalFromString(@"0");
[graph addPlot:highPlot];
// Create the Savings Marker Plot
selectedCoordination = 2;
touchPlot = [[[CPTScatterPlot alloc] initWithFrame:CGRectNull] autorelease];
touchPlot.identifier = kLinePlot;
touchPlot.dataSource = self;
touchPlot.delegate = self;
[self applyTouchPlotColor];
[graph addPlot:touchPlot];
[pool drain];
}
РЕДАКТИРОВАТЬ:
Было получено следующее решение: A. удалить graph.defaultPlotSpace перед инициализацией пространств печати.B. добавление обоих пробелов
[graph addPlotSpace:plotSpace2];
[graph addPlotSpace:plotSpace];
C.присвоить оба участка своему собственному пространству
[graph addPlot:highPlot toPlotSpace:plotSpace];
[graph addPlot:highPlot2 toPlotSpace:plotSpace2];