divyavamsee / core-plot

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

crash IN draw long bar chart #396

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When i try to draw long bar chart with a lot data, CP used all my memory and i 
get a crash.
I use iPhone 4s & 5.0 OS

Could you please help me with fixing this problem?

Original issue reported on code.google.com by IrDidkov...@gmail.com on 25 Jan 2012 at 2:15

GoogleCodeExporter commented 9 years ago
How much data? Doubles or NSDecimals? How many fields are coming from the 
datasource (location, tip, base)?

Original comment by eskr...@mac.com on 26 Jan 2012 at 12:19

GoogleCodeExporter commented 9 years ago
I use NSNumber, decimal
i get 400 numbers from data, so i have 400 bars on the graph
i use scrollView for view all graph on the screen.

But the CP use a lot memory when build graph an i get a crash.
if i get less numbers from data, everything good.

Original comment by i...@ciklum.com on 26 Jan 2012 at 9:08

GoogleCodeExporter commented 9 years ago
What are the dimensions of the graph inside the scroll view? You might be 
running into a limitation of Core Animation or simply running out of graphics 
memory if it's too big.

Original comment by eskr...@mac.com on 26 Jan 2012 at 12:03

GoogleCodeExporter commented 9 years ago
the width of graph inside scrollView = 4980
Yes, not enough memory  of device and i get a crash?
how can i fix this problem?
may by i can use [graph reloadData] when the scrollView begin scroll and draw 
graph by pieces? 

Original comment by i...@ciklum.com on 26 Jan 2012 at 12:33

GoogleCodeExporter commented 9 years ago
Can you just use the built-in scrolling and eliminate the scroll view? This has 
the advantage of being able to keep the axes visible (if you use axis 
constraints) and titles properly positioned as the graph scrolls.

Original comment by eskr...@mac.com on 27 Jan 2012 at 2:23

GoogleCodeExporter commented 9 years ago
i try to use for that 
plotSpace.allowsUserInteraction = YES;
and
-(CPPlotRange *)plotSpace:(CPPlotSpace *)space 
willChangePlotRangeTo:(CPPlotRange *)newRange 
forCoordinate:(CPCoordinate)coordinate

but graph anyway crash 

what property/methods of CP i have to use to do this?

Original comment by IrDidkov...@gmail.com on 27 Jan 2012 at 6:39

GoogleCodeExporter commented 9 years ago
Start simple. The first statement by itself (allowsUserInteraction = YES) 
should be enough. Only use the delegate if you need to control the scrolling 
after you get it working. Depending on what you're doing, you might be able to 
use the global ranges on the plot space to limit the scrolling without having a 
delegate at all.

Did you make the hosting view smaller and remove the scroll view? It should be 
no larger than the device screen or even smaller if there are other UI elements 
you want to keep on screen with the graph.

If you're still having trouble, please post the crash log so we can see where 
the problem is.

Original comment by eskr...@mac.com on 28 Jan 2012 at 3:29

GoogleCodeExporter commented 9 years ago
Hi!
i have tried to make Bar graph without scrollView screenshot (1,2)
but again have a memory crash
I can't show you crash log because my app just close without any log and 
exception and before closing call method - (void)didReceiveMemoryWarning

on screenshot 3 you can see how increase memory when chart begin build
it use 173MB of memory ((
i use iPhone 4s and iOS 5.0

Original comment by i...@ciklum.com on 1 Feb 2012 at 10:47

Attachments:

GoogleCodeExporter commented 9 years ago
What version of Core Plot are you using? Have you checked for leaks? How are 
you creating the text labels? What labeling policy are you using on the x-axis?

Original comment by eskr...@mac.com on 2 Feb 2012 at 3:38

GoogleCodeExporter commented 9 years ago
i use vision CorePlot_0.9
I have checked of leaks and no i have not leaks
I have creating labels for x-axis by following code 

CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) 
                                                   length:CPDecimalFromInteger(maxXRange+1)];

    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
    CPXYAxis *x = axisSet.xAxis;
    x.axisLineStyle = lineStyle;
    x.majorTickLineStyle = lineStyle;
    x.minorTickLineStyle = lineStyle;
    x.majorIntervalLength = CPDecimalFromString(@"1");
    NSString *xCoord = [NSString stringWithFormat:@"%f", minYRange];
    x.orthogonalCoordinateDecimal = CPDecimalFromString(xCoord);

    // Define some custom labels for the data elements
    x.labelRotation = M_PI/4;
    x.labelingPolicy = CPAxisLabelingPolicyNone;
    x.labelOffset = 10.0f;

    x.axisLineStyle.lineColor = [CPColor whiteColor];

    NSMutableArray *customTickLocations = [NSMutableArray array];
    NSMutableArray *xAxisLabels = [NSMutableArray array];

    if (isNoGraph == NO) {
    for (int i=0; i < [self.rowsName count]; i++) {

        NSString *row = [[self.rowsName objectAtIndex:i] objectAtIndex:0];
        [xAxisLabels addObject:row];
        if (isLineChart)            
            [customTickLocations addObject:[NSDecimalNumber numberWithInt:i+1]];
        else
            [customTickLocations addObject:[NSDecimalNumber numberWithInt:i]];
    }
    }

    NSUInteger labelLocation = 0;

    CPMutableTextStyle *textStyle = [x.labelTextStyle mutableCopy];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        textStyle.fontSize = 9;
    }
    textStyle.color = [CPColor whiteColor];
    x.labelTextStyle = textStyle;

    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
    for (NSNumber *tickLocation in customTickLocations) {
        CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];

        newLabel.tickLocation = [tickLocation decimalValue];
        newLabel.offset = x.labelOffset + x.majorTickLength - 15;
        newLabel.rotation = M_PI/4;
        [customLabels addObject:newLabel];
        [newLabel release];

    }

    x.axisLabels =  [NSSet setWithArray:customLabels];

Original comment by IrDidkov...@gmail.com on 2 Feb 2012 at 12:47

GoogleCodeExporter commented 9 years ago
I don't see any problems with the code you posted. I plugged it into one of the 
samples in the Plot Gallery app and it worked fine with even 10,000 bars. No 
crashes or runtime errors.

Original comment by eskr...@mac.com on 10 Feb 2012 at 3:36

GoogleCodeExporter commented 9 years ago
Does this crash still occur with Core Plot 1.0 or later?

Original comment by eskr...@mac.com on 21 Mar 2012 at 11:12

GoogleCodeExporter commented 9 years ago
Yes it steal here :(
We are making our own classes for drawing charts.
Thanks for the answers :)

Original comment by IrDidkov...@gmail.com on 23 Mar 2012 at 8:35

GoogleCodeExporter commented 9 years ago
Unable to reproduce this issue.

Original comment by eskr...@mac.com on 23 Mar 2012 at 10:41