I just added a Core Plot view to my tutorial based application ( http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application ). I put the Core Plot drawing code in the windowDidLoad method of the window controller for the window in which I included CPLayerHostingView. Code for the chart:
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
length:CPDecimalFromFloat(12)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
length:CPDecimalFromFloat(30)];
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor blackColor];
lineStyle.lineWidth = 2.0f;
axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
axisSet.xAxis.axisLabelOffset = 3.0f;
axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;
axisSet.yAxis.axisLabelOffset = 3.0f;
CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
xSquaredPlot.identifier = @"X Squared Plot";
xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
xSquaredPlot.dataSource = self;
[graph addPlot:xSquaredPlot];
When creating, I get the following errors:
". objc_class_name_CPPlotRange" referenced: literal-pointer @__ OBJC @__ cls_refs @CPPlotRange in HistogramWindowController.o
"_ CPDecimalFromFloat", : - [HistogramWindowController windowDidLoad] HistogramWindowController.o - [HistogramWindowController windowDidLoad] HistogramWindowController.o - [HistogramWindowController windowDidLoad] HistogramWindowController.o - [HistogramWindowController windowDidLoad] HistogramWindowController.o
". objc_class_name_CPLineStyle", : literal-pointer @__ OBJC @__ cls_refs @CPLineStyle HistogramWindowController.o
". objc_class_name_CPXYGraph", : literal-pointer @__ OBJC @__ cls_refs @CPXYGraph HistogramWindowController.o
". objc_class_name_CPScatterPlot", : literal-pointer @__ OBJC @__ cls_refs @CPScatterPlot HistogramWindowController.o
". objc_class_name_CPPlotSymbol", : literal-pointer @__ OBJC @__ cls_refs @CPPlotSymbol HistogramWindowController.o
". objc_class_name_CPColor", : literal-pointer @__ OBJC @__ cls_refs @CPColor HistogramWindowController.o
". objc_class_name_CPFill", : literal-pointer @__ OBJC @__ cls_refs @CPFill HistogramWindowController.o
ld:
collect2: ld 1
. - , ?