Closed GoogleCodeExporter closed 8 years ago
The -numberOfRecordsForPlot: method is being sent to the wrong object. Make
sure the datasource is set correctly and that the datasource object implements
this method.
Original comment by eskr...@mac.com
on 14 Jun 2013 at 1:21
CPTBarPlot *aaplPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor redColor]
horizontalBars:NO];
aaplPlot.identifier = CPDTickerSymbolAAPL;
CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineColor = [CPTColor lightGrayColor];
barLineStyle.lineWidth = 0.5;
CPTGraph *graph = self.hostView.hostedGraph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.delegate = self;
CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
[xRange expandRangeByFactor:CPTDecimalFromCGFloat(1.1f)];
plotSpace.xRange = xRange;
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
[yRange expandRangeByFactor:CPTDecimalFromCGFloat(1.2f)];
plotSpace.yRange = yRange;
CGFloat barX = _0DBarInitialX;
aaplPlot.barWidth = CPTDecimalFromDouble(_0DBarWidth);
aaplPlot.barOffset = CPTDecimalFromDouble(barX);
aaplPlot.lineStyle = barLineStyle;
[graph addPlot:aaplPlot toPlotSpace:plotSpace];
Here is the code that I use within it's own UIViewController class.
I basically went through an entire tutorial and used their code to add the BAR
GRAPH to the subview :
http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2
Adding their scatter plot was no issue but I real issue is when I add BAR plots
to a CPTGraph.
If you look at the tutorial code... It's all there. The only modification I
made was in the -initPlot function.
self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc]
initWithFrame:CGRectMake(0, 0, 320, 170)];
[self.view addSubview:self.hostView];
Which was the same thing I did to the scatter plot graph in the same tutorial.
I also took away the storyboard and just extracted the .h and .m files as well
as the datasources they used and identifiers.
I set the CPTBarPlot object's datasource to "self" and that basically makes it
crash. I did more debugging and that's what I found out. I even tried to make
static CPTBarPlot objects and added them to the CPTGraph object but still...
crash....
When I don't set the datasource... no crash occurs, but there are then no bars
to be seen, just the graph with no plots.
I also implement -numberOfRecordsForPlot: within the same ViewController as the
BarGraph class.
I may not totally unnderstand your wording as I am very new Objective-C
programmer... 3 months of excessive coding.... but I should most likely know
what your talking about... :(
Original comment by jsettin...@gmail.com
on 15 Jun 2013 at 1:30
aaplPlot.dataSource = self;
This line was commented out since it kept crashing my code....
It was implemented after the second line "aaplPlot.identifier =
CPDTickerSymbolAAPL;"
Original comment by jsettin...@gmail.com
on 15 Jun 2013 at 1:32
A few minutes with Google leads me to believe this is a memory management issue
in your app. The dataSource property holds a weak reference to the datasource.
You need to make sure that the datasource object is not released during the
lifetime of the plot.
Original comment by eskr...@mac.com
on 15 Jun 2013 at 1:45
OMG Wow.... THANK YOU THANK YOU THANK YOU.....
After one line of code.... everything runs perfectly.....
[aaplPlot.dataSource retain];
THANK YOU THANK YOU THANK YOU!!!!!
I implemented this line after setting the CPTBarPlot object "aaplPlot"'s
datasource.
Like eskroch@mac.com said, the datasource must not be released during the
lifetime of the plot.
Thank you thank you thank you.
Original comment by jsettin...@gmail.com
on 16 Jun 2013 at 4:19
Original comment by eskr...@mac.com
on 16 Jun 2013 at 12:19
Original issue reported on code.google.com by
jsettin...@gmail.com
on 13 Jun 2013 at 11:02Attachments: