Проблема со столбчатой ​​диаграммой Coreplot, показывающая тикеры в нужном месте?

Я работаю над приложением для iphone barchart. Я не получаю значение метки тикера в соответствии с изображением ниже:

введите здесь описание изображения

barChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTStocksTheme];
[barChart applyTheme:theme];
CPTGraphHostingView *hostingView =(CPTGraphHostingView *)self.view;
//[self.scrollview addSubview:hostingView];
hostingView.hostedGraph = barChart;

// Border
barChart.plotAreaFrame.borderLineStyle = nil;
barChart.plotAreaFrame.cornerRadius = 10.0f;

// Paddings
barChart.paddingLeft = 0.0f;
barChart.paddingRight = 0.0f;
barChart.paddingTop = 0.0f;
barChart.paddingBottom = 0.0f;

barChart.plotAreaFrame.paddingLeft = 70.0;
barChart.plotAreaFrame.paddingTop = 20.0;
barChart.plotAreaFrame.paddingRight = 20.0;
barChart.plotAreaFrame.paddingBottom = 80.0;

// Graph title
barChart.title = @"Statistics";
CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle];
textStyle.color = [CPTColor greenColor];
textStyle.fontSize = 20.0f;
textStyle.textAlignment = CPTTextAlignmentCenter;
barChart.titleTextStyle = textStyle;
barChart.titleDisplacement = CGPointMake(0.0f, -20.0f);
barChart.titlePlotAreaFrameAnchor = CPTRectAnchorTop;

// Add plot space for horizontal bar charts
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)barChart.defaultPlotSpace;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(15.0f)];
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(20.0f)];
plotSpace.globalXRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(20.0f)];
    plotSpace.globalYRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(20.0f)];
plotSpace.allowsUserInteraction=TRUE;



CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barChart.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.axisLineStyle = nil;
x.majorTickLineStyle = nil;
[x setMinorTickLineStyle:CPTLinearBlendingMode];
x.majorIntervalLength = CPTDecimalFromString(@"10");
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
x.title = @"Quiz Date";
x.majorTickLength=10.0f;
x.titleLocation = CPTDecimalFromFloat(7.5f);
x.titleOffset = 60.0f;
x.labelOffset=5.0f;

// Define some custom labels for the data elements
x.labelRotation = M_PI/2;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
//NSDecimalNumber add=0;


CPTPlotRange *globalxrange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(1000.0f)];
plotSpace.globalXRange=globalxrange; 

NSMutableArray *customTickLocations = [[NSMutableArray alloc]init];
NSDecimalNumber *num = nil;
for (int i=0;i<[arr count];i++) {
    num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:i*5];
    [customTickLocations addObject:num];
}

NSArray *xAxisLabels =[[NSMutableArray alloc]initWithArray:labelValue]; //[NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations) {
    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
    newLabel.tickLocation = [tickLocation decimalValue];
    newLabel.offset =x.labelOffset+ x.majorTickLength ;
    newLabel.rotation =M_PI/2;
    NSLog(@"-=-=-=--=-=-=- %d",x.labelOffset+ x.majorTickLength );
    [customLabels addObject:newLabel];
    [newLabel release];
}
x.axisLabels =  [NSSet setWithArray:customLabels];





CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy=CPTAxisLabelingPolicyAutomatic;
y.axisLineStyle = nil;
y.majorTickLineStyle = nil;
y.minorTickLineStyle = nil;
y.majorIntervalLength = CPTDecimalFromString(@"1");
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
y.title = @"No. of Questions";
y.titleOffset = 50.0f;
y.titleLocation = CPTDecimalFromFloat(150.0f);

// First bar plot
CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
barPlot.baseValue = CPTDecimalFromString(@"0");
barPlot.dataSource = self;
barPlot.barWidth=CPTDecimalFromFloat(1.0f);
barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0)                                       length:CPTDecimalFromDouble(x.labelOffset + x.majorTickLength)];
barPlot.barOffset =CPTDecimalFromFloat(1.0f);
barPlot.barCornerRadius = 2.0f;
barPlot.identifier = @"Bar Plot 1";

[barChart addPlot:barPlot toPlotSpace:plotSpace];
    `// barPlot.barOffset = CPTDecimalFromFloat(0.25f);
barPlot.barCornerRadius = 2.0f;
barPlot.identifier = @"Bar Plot 2";
[barChart addPlot:barPlot toPlotSpace:plotSpace];`

// third bar plot
barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor redColor] horizontalBars:NO];
barPlot.dataSource = self;
barPlot.barWidth=CPTDecimalFromFloat(1.0f);
barPlot.baseValue = CPTDecimalFromString(@"0"); 
barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0)length:CPTDecimalFromDouble(x.labelOffset + x.majorTickLength)];
barPlot.barOffset =CPTDecimalFromFloat(3.0f);
barPlot.barCornerRadius = 2.0f;
barPlot.identifier = @"Bar Plot 3";
[barChart addPlot:barPlot toPlotSpace:plotSpace];


// arrayWithObjects:[NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], nil];}

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
return [arr count];`}`

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index `{`
NSDecimalNumber *num = nil;
if ( [plot isKindOfClass:[CPTBarPlot class]] ) {
    switch ( fieldEnum ) {
        case CPTBarPlotFieldBarLocation:
            num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index];
            break;

        case CPTBarPlotFieldBarTip:
            if ( [plot.identifier isEqual:@"Bar Plot 1"] ) 
                num=[NSDecimalNumber decimalNumberWithString:[totalValues objectAtIndex:index]];

            if ( [plot.identifier isEqual:@"Bar Plot 2"] ) 
                num=[NSDecimalNumber decimalNumberWithString:[correctValues objectAtIndex:index]];

            if ( [plot.identifier isEqual:@"Bar Plot 3"] ) 
                num=[NSDecimalNumber decimalNumberWithString:[wrongArray objectAtIndex:index]];

            break;


        case CPTScatterPlotFieldX:  
            if ( [plot.identifier isEqual:@"Bar Plot 1"] ) 
                num=[NSDecimalNumber decimalNumberWithString:[totalValues objectAtIndex:index]];
            return num;

            if ( [plot.identifier isEqual:@"Bar Plot 2"] ) 
                num=[NSDecimalNumber decimalNumberWithString:[correctValues objectAtIndex:index]];
                return num;

            if ( [plot.identifier isEqual:@"Bar Plot 3"] ) 
                num=[NSDecimalNumber decimalNumberWithString:[wrongArray objectAtIndex:index]];
            return num;

            break;


    }
}

return num;`}`

-(CPTFill *) barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSNumber *)index; 
{
return nil;
}

person abhiTouchmagic    schedule 30.08.2011    source источник
comment
Пожалуйста, помогите мне с этим ... я новичок в графиках iphone и перепробовал все, что мог .......   -  person abhiTouchmagic    schedule 30.08.2011
comment
Можете ли вы описать, что вы подразумеваете под значением метки тикера?   -  person Eric Skroch    schedule 31.08.2011
comment
значение тикера означает, что значения дат ниже оси x должны находиться ниже синей полосы точно, сэр ....   -  person abhiTouchmagic    schedule 31.08.2011


Ответы (1)


Установите barOffset на ноль для графика, который вы хотите выровнять с метками. Установите другие относительно этого. Например:

barPlot1.barOffset = CPTDecimalFromDouble(-1.0);
barPlot2.barOffset = CPTDecimalFromDouble( 0.0);
barPlot3.barOffset = CPTDecimalFromDouble( 1.0);

Вам также нужно будет отрегулировать xRange области графика, чтобы первая пара полос оставалась видимой.

person Eric Skroch    schedule 01.09.2011