Question

I'm trying to use a scatter plot from Core Plot in my iOS application. I set up Core Plot as the Core Plot wiki says, and then I copy PlotItem.h/m, PlotGallery.h/m and SimpleScatterPlot.h/m from the included Plot Gallery project into my project. The code

CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
SimpleScatterPlot *scatterPlot = [[SimpleScatterPlot alloc]init];
[scatterPlot generateData];
[scatterPlot renderInLayer:hostView withTheme:theme];

runs, and the graph view is shown in my app. But I cannot move the graph view around or tap the plot points as in the Plot Gallery project. How do I set this up right?

Was it helpful?

Solution

The Plot Gallery is a poor starting point for a simple Core Plot demonstration. It has a lot of extra "stuff" to support generating a table view with thumbnails of all the different plots. The -renderInView:withTheme: method is used to make the thumbnail images for the table view. It renders the graph as an image which is why you lose interactivity. Unless you need the flexibility to quickly add new plots to your app and easily support both MacOS and iOS, I would recommend using one of the other examples as a starting point. The architecture is much simpler and easier to understand.

You need to have a CPTGraphHostingView in the visible view hierarchy. Set your graph as its hostedGraph. Look at any of the other example apps to see how to set up the hosting view. The graph setup and datasource code in the Plot Gallery plots (e.g., SimpleScatterPlot) is fine and should work anywhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top