gujjula / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

position of x-Axis is flexible and hides the labels #328

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a problem of the correct presentation of x and y axis. 
I just want to set 2 things:
1. I only wanted to have postive axis
2. the axis-position should be on the left bottom

That what I have :

I have positive axis, but it seems to be floating depenting on the highest 
value from one plot. That means is the highest value = 1 the x-axis is shown at 
the mittle of the screen. Is the highest value = 100, the x-axis is shown at 
the bottom and the labels are not longer visible.

Did you have an idea or tipp to fix this?
Thanks :-)

thats my code:

graph = [[CPTXYGraph alloc] initWithFrame: self.view.bounds];

    CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
    [graph applyTheme:theme];

    hostingView.autoresizesSubviews = YES;     

    [hostingView setHostedGraph:graph];
    graph.paddingLeft = 20.0;
    graph.paddingTop = 20.0;
    graph.paddingRight = 20.0;
    graph.paddingBottom = 20.0;

    plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-0.8f)
                                                    length:CPTDecimalFromFloat(9.0f)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-3.0f) 
                                                    length:CPTDecimalFromInt(highestValue*2)];

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;

    //X-Axis
    axisSet.xAxis.labelRotation = M_PI/4;
    axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;

    NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithFloat:0.8f], [NSDecimalNumber numberWithFloat:1.8f], nil];
    NSArray *xAxisLabels = [NSArray arrayWithObjects:@"total", @"today", nil];
    NSUInteger labelLocation = 0;
    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
    for (NSNumber *tickLocation in customTickLocations) {
        CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:axisSet.xAxis.labelTextStyle];
        newLabel.tickLocation = [tickLocation decimalValue];
        newLabel.offset = -1.0f;
        newLabel.rotation = M_PI/4;
        [customLabels addObject:newLabel];
        [newLabel release];
    }

    axisSet.xAxis.axisLabels =  [NSSet setWithArray:customLabels];

    axisSet.xAxis.visibleRange  = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0)
                                                        length:CPTDecimalFromInteger(4)];

    //Y-Axis
    axisSet.yAxis.majorIntervalLength = CPTDecimalFromFloat(5);
    axisSet.yAxis.minorTicksPerInterval = 4;
    axisSet.yAxis.minorTickLength = 1.0f;
    axisSet.yAxis.majorTickLength = 1.0f;
    axisSet.yAxis.labelOffset = 3.0f;

    axisSet.yAxis.visibleRange  = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0)
                                                               length:CPTDecimalFromInteger(highestValue)];

    //blue Plot
    CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
    barPlot.identifier = @"blue";
    barPlot.barOffset = CPTDecimalFromFloat(0.8f);
    barPlot.dataSource = self;

    [graph addPlot:barPlot toPlotSpace:plotSpace];

    [self.view addSubview:hostingView];
    [graph release];

Original issue reported on code.google.com by hus...@bossmail.de on 6 Sep 2011 at 11:33

GoogleCodeExporter commented 9 years ago
Questions like this belong on the discussion board ( 
http://groups.google.com/group/coreplot-discuss/topics ), not the issue tracker.

You need to set some padding on the plotAreaFrame in addition to the graph. You 
may also need to adjust the plot range. If you need more help, please ask on 
the discussion board.

Original comment by eskr...@mac.com on 7 Sep 2011 at 1:18