0

コア プロットを使用して積み上げ棒グラフを描画できます。私の問題は、積み上げ棒グラフの上にラベルを配置できないことです。バーを作成するために、次のことを行いました

ここに画像の説明を入力

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

以下は私が書いているコードです

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

1 に答える 1

1

labelOffset各プロットの を調整できる場合があります。別のプロットの下に引っかかるのではなく、そのプロットの上にラベルを配置するには、負の値を試してください。

試してみるもう1つのことは、プロットを逆の順序で追加して、下のプロットとそのラベルが上のプロットの上にくるようにすることです。あなたの例では、黄色のプロットが最初、緑色のプロットが 2 番目などになります。

他のすべてが失敗した場合は、プロット スペースの注釈を使用して独自のラベルを作成します。これにより、ラベルの配置もより柔軟になります。たとえば、バーの上ではなく横にラベルを配置できます。

于 2013-09-18T01:14:48.370 に答える