首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >条形图的标签没有显示在条形图的顶部。

条形图的标签没有显示在条形图的顶部。
EN

Stack Overflow用户
提问于 2013-09-17 07:21:24
回答 1查看 294关注 0票数 0

我可以画一个堆叠的条形图的帮助下的核心图形。我的问题是我不能把标签放在堆叠的条形图上。为了创建条形图,我做了以下工作

代码语言:javascript
复制
for (NSString *set in [[barChartidentifiers allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]) {
    CPTBarPlot *plot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
    plot.lineStyle = barLineStyle;
    CGColorRef color = ((UIColor *)[barChartidentifiers objectForKey:set]).CGColor;
    plot.fill  = [CPTFill fillWithColor:[CPTColor colorWithCGColor:color]];
    if (firstPlot) {
        plot.barBasesVary = NO;
        firstPlot  = NO;
    } else {
        plot.barBasesVary = YES;
    }
    plot.barWidth = CPTDecimalFromFloat(0.5);
    plot.barsAreHorizontal  = NO;
    plot.labelTextStyle = [CPTTextStyle textStyle];
    plot.dataSource = self;
    plot.identifier = set;
    [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
}

下面是我正在写的代码

代码语言:javascript
复制
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
    NSNumber *num;
    if (fieldEnum == 0) {
        num = [NSNumber numberWithInt:index];
    }

    else {
        double offset = 0;
        if (((CPTBarPlot *)plot).barBasesVary) {
            for (NSString *set in [[barChartidentifiers allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]) {
                if ([plot.identifier isEqual:set]) {
                    break;
                }
                offset += [[[data objectForKey:[dates objectAtIndex:index]] objectForKey:set] doubleValue];


            }
        }

        //Y Value
        if (fieldEnum == 1) {
            num =[NSNumber numberWithDouble:[[[data objectForKey:[dates objectAtIndex:index]] objectForKey:plot.identifier] doubleValue] + offset];
        }

        //Offset for stacked bar
        else {
            num =[NSNumber numberWithDouble:offset];
        }
    }

    //NSLog(@"%@ - %d - %d - %f", plot.identifier, index, fieldEnum, num);

    return num;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-18 01:14:48

您可能可以调整每个地块的labelOffset。尝试一个负值来标记它的情节,而不是被困在另一个情节之下。

另一件要尝试的事情是以相反的顺序添加地块,这样较低的地块和它们的标签就在上面。在你的例子中,黄色的地块将是第一个,绿色的第二个,等等。

如果所有这些都失败了,那么使用绘图空间注释来制作您自己的标签。这也会给标签的定位带来更大的灵活性。例如,您可以将标签放在条子旁边而不是顶部。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18843672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档