Core plot : how to change plotSpace.xRange dynamically when device orientation change?

941 Views Asked by At

I've got an iOS app whith many charts. I would like to modify the xRange value when the charts is displayed in landscape mode but I can't have Core Plot doing this.

I tried to totally recreate the graph by calling

[graph removePlotWithIdentifier:@"myGraphName"];

in "WillRotateToInterfaceOrientation" and then building my graph again with new xRange but it doesn't worked.

I would like CorePlot to dynamically adapt the xRange depending on the device orientation.

I've got this code to manage a different xRange depending on the device orientation on first creation of the graph:

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationPortrait
   || orientation == UIInterfaceOrientationPortraitUpsideDown) {

    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(lengthToDisplay/2) length:CPTDecimalFromInteger(lengthToDisplay/2)];

} else if(orientation == UIInterfaceOrientationLandscapeLeft
          || orientation == UIInterfaceOrientationLandscapeRight) {

    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(lengthToDisplay) length:CPTDecimalFromInteger(lengthToDisplay)];
}

It works fine. But if the graph is already displayed and I change the device orientation nothing happens. I tried to put this code in "WillRotateToInterfaceOrientation" but again, nothings happens.

0

There are 0 best solutions below