kaiserfarrell / core-plot

Automatically exported from code.google.com/p/core-plot
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Adding BarPlotController:UIViewController view in a subview of another UIView. #548

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a CPTGraph
2. Add a CPTBarplot object to the CPTGraph
3. Add the CPTGraph that's view is within a CPTGraphHostingView
4. Instantiate the CPTGraphHostingView in a seperate class and add the 
HostingView to a UIView's subview

What is the expected output? What do you see instead?
Adding a Graph whose plots are CPTBarPlot within a subview of a UIView of 
several other UIViews in one UIViewController

What version of the product are you using? On what operating system?
CorePlot 1.2 / Coding on my MAC OS 10.8 for iOS 6.1

Please provide any additional information below.

Here is the code that makes my application crash
[graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];

When I add the BarGraph UIViewController class's "view" to an existing UIView's 
subview, the app crashes and gives me no debugging errors, just BAD_EXCESS with 
some assembly language.

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,150,320,200)];
[self.view addSubview:view];

BarGraphViewController *barplotview = [[BarGraphViewController alloc] init];
    barplotview.hostView.frame = CGRectMake(csView.bounds.origin.x, csView.bounds.origin.y, csView.bounds.size.width , csView.bounds.size.height);
    [csView addSubview:barplotview.view];

Also, this issue does not occur when I use the CPTScatterPlot objects, just 
CPTBarPlot objects.

Here is one issue that pops up out of nowhere sometimes....

-[__NSCFType numberOfRecordsForPlot:]: unrecognized selector sent to instance 
0x9f7cd10

Heres another error....
-[NSURL numberOfRecordsForPlot:]: unrecognized selector sent to instance 
0xd2b3ff0

These errors don't show up all together.... I compile and see different errors 
everytime.... Just for CPTBarPlot objects...

Attached is the view of the WORKING scatterplot... But when I add a bar graph 
... CRASHes occur with random errors that are sometimes different...

Both the scatter plot class and the bargraph class are implemented the same... 
basically....

But like I said... the error occurs when I use
[graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];

Hopefully there is an easy solution because debugging this has been 
unsuccessful and stressful.

Original issue reported on code.google.com by jsettin...@gmail.com on 13 Jun 2013 at 11:02

Attachments:

GoogleCodeExporter commented 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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago

Original comment by eskr...@mac.com on 16 Jun 2013 at 12:19