1

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.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
Flopi
  • 73
  • 1
  • 5
  • Does this code actually execute? Use an `NSLog` statement to find out. What version of iOS are you testing on? The way device rotation is handled changed starting with iOS 6. See Apple's [View Controller Programming Guide for iOS](http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html). – Eric Skroch Oct 19 '12 at 23:14
  • This code execute : I haven't put everything here but I handle other change depending on device orientation and those change are done when device orientation change. I've tried it on iOS6 and earlier. Can't understand why the range isn't updated.... – Flopi Oct 23 '12 at 10:40
  • What is `plotSpace`? Is it a reference to the plot space actually in use by the graph? What is the value of `lengthToDisplay`? What type is it? – Eric Skroch Oct 24 '12 at 23:49
  • Yes, plotSpace is a reference to the plotSpace actually in use by the graph : `CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace*)graph.defaultPlotSpace;` and lengthToDisplay is calculated based of the number of points to display, it's a NSInteger : `NSInteger lengthToDisplay = [Data_graph count] * graphTimeFrame;` – Flopi Oct 26 '12 at 08:49

0 Answers0