Iphone Coreplot条形图问题是否在正确的位置显示标记?

Iphone Coreplot条形图问题是否在正确的位置显示标记?,iphone,core-plot,Iphone,Core Plot,我正在开发一个iphone条形图应用程序。我没有按照下图所示获取股票代码标签值: barChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero]; CPTTheme *theme = [CPTTheme themeNamed:kCPTStocksTheme]; [barChart applyTheme:theme]; CPTGraphHostingView *hostingView =(CPTGraphHostingView *)self.vie

我正在开发一个iphone条形图应用程序。我没有按照下图所示获取股票代码标签值:

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;
}

barChart=[[CPTXYGraph alloc]initWithFrame:CGRectZero];
CPTTheme*theme=[CPTTheme themeName:KCPTStocksTime];
[条形图应用主题:主题];
CPTGraphHostingView*hostingView=(CPTGraphHostingView*)self.view;
//[self.scrollview addSubview:hostingView];
hostingView.hostedGraph=条形图;
//边界
barChart.plotAreaFrame.borderLineStyle=nil;
barChart.plotAreaFrame.cornerRadius=10.0f;
//衬垫
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;
//图表标题
barChart.title=@“统计”;
CPTMutableTextStyle*textStyle=[CPTTextStyle textStyle];
textStyle.color=[CPTColor greenColor];
textStyle.fontSize=20.0f;
textStyle.textAlignment=CPTTextAlignmentCenter;
barChart.titleTextStyle=文本样式;
barChart.titleDisplacement=CGPointMake(0.0f,-20.0f);
barChart.titlePlotAreaFrameAnchor=CPTRectAnchorTop;
//为水平条形图添加打印空间
CPTXYPlotSpace*plotSpace=(CPTXYPlotSpace*)条形图。默认plotSpace;
plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)长度:CPTDecimalFromFloat(15.0f)];
plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)长度:CPTDecimalFromFloat(20.0f)];
plotSpace.globalXRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)长度:CPTDecimalFromFloat(20.0f)];
plotSpace.globalYRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)长度:CPTDecimalFromFloat(20.0f)];
plotSpace.allowUserInteraction=TRUE;
CPTXAxisSet*axisSet=(CPTXAxisSet*)条形图。axisSet;
CPTXYAxis*x=axisSet.xAxis;
x、 axisLineStyle=nil;
x、 majorTickLineStyle=nil;
[x setMinorTickLineStyle:CPTLinearBlendingMode];
x、 majorIntervalLength=CPTDecimalFromString(@“10”);
x、 正交坐标CIMAL=CPTDecimalFromString(@“0”);
x、 标题=@“测验日期”;
x、 majorTickLength=10.0f;
x、 滴定位置=CPTDecimalFromFloat(7.5f);
x、 标题偏移=60.0f;
x、 labelOffset=5.0f;
//为数据元素定义一些自定义标签
x、 labelRotation=M_PI/2;
x、 labelingPolicy=CPTAxisLabelingPolicyNone;
//n小数相加=0;
CPTPlotRange*globalxrange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f)长度:CPTDecimalFromDouble(1000.0f)];
plotSpace.globalXRange=globalXRange;
NSMutableArray*customTickLocations=[[NSMutableArray alloc]init];
NSDecimalNumber*num=nil;

对于(int i=0;i将要与标签对齐的绘图的
barOffset
设置为零。设置与该绘图相关的其他绘图。例如:

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

您还需要调整绘图空间的
xRange
,以保持前两个条形图可见。

请帮助我……我对iphone图形不熟悉,并尝试了所有我能尝试的东西……。您能描述一下“股票标签值”是什么意思吗?股票价值是指x轴以下日期的价值应准确地低于蓝色条,先生。。。。