I have added CPTSCatterPlot and CPTBarPlot for two CPTPlotSpaces in one graph.I have worten a method to reloadData for the graph but not working so correctly.I want two of graph reload the y-axis labels after I have called the ScaleToFit method. Here is my Code:
plotSpace1 = (CPTXYPlotSpace*)graph.defaultPlotSpace;
barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithCGColor:TJCOLOR1.CGColor] horizontalBars:_isHorizontal];
barPlot.identifier = @"Bar";
barPlot.delegate = self;
barPlot.dataSource = self;
[graph addPlot:barPlot toPlotSpace:plotSpace1];
[plotSpace1 scaleToFitPlots:[NSArray arrayWithObject:barPlot]];
plotSpace2 = [[CPTXYPlotSpace alloc]init];
[graph addPlotSpace:plotSpace2];
scatterPlot = [[CPTScatterPlot alloc]init];
scatterPlot.identifier = @"Scatter";
scatterPlot.delegate = self;
scatterPlot.dataSource = self;
[graph addPlot:scatterPlot toPlotSpace:plotSpace2];
[plotSpace2 scaleToFitPlots:[NSArray arrayWithObject:scatterPlot]];
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.tickDirection = CPTSignNegative;
x.labelOffset = -20.0f;
x.labelTextStyle = axisTextStyle;
[self xlabelS:x];
x.hidden = YES;
// x.axisConstraints = [CPTConstraints constraintWithLowerOffset:-3.0];
y = [[CPTXYAxis alloc]initWithFrame:CGRectZero];
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.plotSpace = plotSpace1;
y.coordinate = CPTCoordinateY;
y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0);
y.labelExclusionRanges = nil;
y.labelTextStyle = axisTextStyle;
y.orthogonalCoordinateDecimal = CPTDecimalFromCGFloat(-0.5);
y.hidden = YES;
y2 = [[CPTXYAxis alloc]initWithFrame:CGRectZero];
y2.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y2.plotSpace = plotSpace2;
y2.coordinate = CPTCoordinateY;
y2.orthogonalCoordinateDecimal = CPTDecimalFromFloat([_titleArray count]);
y2.titleLocation = CPTDecimalFromInt(0);
y2.labelExclusionRanges = nil;
y2.titleOffset = -10.0f;
y2.labelOffset = -40.0f;
y2.labelTextStyle = axisTextStyle;
y2.hidden = YES;
y2.majorGridLineStyle = gridLineStyle;
NSArray *axies = [NSArray arrayWithObjects:x,y,y2, nil];
// [axies addObject:y2];
graph.axisSet.axes = axies;
- (void)reloadData
{
[graph.plotAreaFrame.plotArea removeAllAnnotations];
[graph reloadData];
[plotSpace1 scaleToFitPlots:[NSArray arrayWithObject:barPlot]];
[plotSpace2 scaleToFitPlots:[NSArray arrayWithObject:scatterPlot]];
CPTXYAxisSet *axisSet = (CPTXYAxisSet*)hostingView.hostedGraph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
[self xlabelS:x];
}
- (void)xlabelS:(CPTXYAxis *)x
{
NSMutableSet *xLabels = [NSMutableSet set];
NSMutableSet *xLocations = [NSMutableSet set];
NSInteger i = 0;
for (NSString *date in _titleArray) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:date textStyle:x.labelTextStyle];
CGFloat location = i++;
label.tickLocation = CPTDecimalAdd(CPTDecimalFromCGFloat(location), barPlot.barWidth);
label.offset = x.majorTickLength;
if (label) {
[xLabels addObject:label];
[xLocations addObject:[NSNumber numberWithFloat:location]];
}
}
// x.labelingOrigin = CPTDecimalFromInt(1);
x.axisLabels = xLabels;
y.plotSpace = plotSpace1;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y2.orthogonalCoordinateDecimal = CPTDecimalFromFloat([_titleArray count] );
}
Only the right y-axies relabeled correctly.Was anywhere I code wrong?Help me please!
The y-axis is tied to plotSpace1
. It is independent of the other plot space. No matter how plotSpace2
changes, it won't affect the y-axis. If you want to see both scales, you'll need to add another y-axis to plotSpace2
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.