2

I am using core plot 1.0 in my iphone app. All works fine, graphs are drawing perfectly, But I am facing a weird problem that All the controls on graph page(CPTPGraphHostingView) are mirrored.

Ie: On that xib file, I set the class in class Identity of top UIView to CPTPGraphHostingView, then problem arises.

Please help me how to solve this. The controls appear correctly in interface builder, but when I run the project all gets messed up.

Even I have tried to add background Image programatically, but that also is mirrored.

wjl
  • 7,143
  • 1
  • 30
  • 49
  • 1
    possible duplicate of [ios sub view appears upside down in simulator](http://stackoverflow.com/questions/9479202/ios-sub-view-appears-upside-down-in-simulator) – Eric Skroch Mar 30 '12 at 00:37
  • @EricSkroch Thanks I got the solution from your answer in the link you mentioned. –  Mar 30 '12 at 07:09

2 Answers2

4

References for this answer:

I came to know that the whole CPTPGraphHostingView is inverted upside down to support both Mac OS and iOS. This is by design and is not a bug.

So the solution from the given links is that:

  1. Add two Views to your xib file, one of type CPTPGraphHostingView(for adding graph) and the other of type UIView(for adding any other ui controls, backgrounds etc). You can modify the type of View by modifying Class field under the heading Class Identity in View Identity tab of File's Owner window.
  2. Now add the graph to CPTPGraphHostingView and add other ui controls to the other view(UIView)
  3. End of story

UPDATE: If you add CPTPGraphHostinView to interface, no other components will be visible, for that you'll have to set theme, and fill of CPTXYGraph to nil. Ie add following lines after you initialize your CPTXYGraph:

CPTTheme *theme = nil;
[barChart applyTheme:theme]; // barChart is my CPTXYGraph

barChart.fill = nil;
barChart.plotAreaFrame.fill = nil;

NOTE:: Add CPTPGraphHostingView such that it is child of top level UIView, and other components are in top level UIView, and CPTPGraphHostingView is above all other components.

Community
  • 1
  • 1
  • 8
    "A very pathetic design approach though" - Seeing as how I designed this, I take offense to that comment. As I explain [here](http://stackoverflow.com/a/868621/19679), UIViews by default flip the coordinate system of CALayers contained within them. NSViews on the Mac and normal Quartz contexts do not flip this coordinate system. Therefore, in order to use the same rendering code on both Mac and iOS, one of the two needs to be inverted by Core Plot. Given that UIViews are the ones doing the flipping, we decided to invert that transformation on iOS so that it matched the Mac. – Brad Larson Mar 30 '12 at 20:39
  • @BradLarson Ok, I am sorry, removed those comments. –  Mar 30 '12 at 21:32
  • I have added UIView and an image view inside it alongside CPTGraphHostingVIew in xib. But i only get to see the graph but not the view with image.Is the graph view overlapping with UIView? Where am i going wrong? – TechnocraT Apr 10 '12 at 12:51
  • @TechnocraT I have updated my answer. This will solve your problem IA –  Apr 10 '12 at 13:20
  • @djaqeel I've added those lines setting nil, but it doesn't affect the output. I added views as View(UIView)-> Image view(UIImageView) , Graph hosting view (CPTGraphHostingView) – TechnocraT Apr 10 '12 at 13:49
  • @TechnocraT, You have to add those lines right after initializing the graph. If you did the same, please visit this link http://stackoverflow.com/questions/5132253/core-plot-custom-theme –  Apr 11 '12 at 07:09
  • @djaqeel Dude I dint get you method working in my app but as i only had to add image i've done as follows: `CPTImage* background = [[CPTImage alloc] initWithCGImage:[UIImage imageNamed:@"Myimage.png"].CGImage]; pieChart.plotAreaFrame.fill = [CPTFill fillWithImage:background];` But i still need to get it working the way you mentioned. – TechnocraT Apr 11 '12 at 09:53
0

Try self.view = (CPTPGraphHostingView *)view

Vignesh
  • 10,205
  • 2
  • 35
  • 73