核心图,自定义标签和刻度线

时间:2010-10-18 14:29:19

标签: core-plot

我正在使用Core Plot alpha版本0.2并生成带有自定义标签的图表。标签出现在正确的位置,但我没有刻度线。我尝试了这些设置的每个组合:

x.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@“5”] decimalValue]; x.minorTicksPerInterval = 0; x.majorTickLineStyle = lineStyle; x.minorTickLineStyle = lineStyle; x.axisLineStyle = lineStyle; x.minorTickLength = 5.0f; x.majorTickLength = 7.0f; x.tickDirection = CPSignNegative;

我还使用以下方法在图表底部添加了填充:

graph.plotAreaFrame.paddingBottom = 10.0;

具有向上移动X轴的效果,但没有可见的刻度线。这似乎应该非常简单,在自定义标签的位置生成刻度线。但我认为没有办法做到这一点。

想法?

** * * 以下是我用于生成标签和刻度线的代码,没有运气 *

for (int i = 0; i < [xAxisLabels count]; i++) {
    NSDictionary * labelDict = [xAxisLabels objectAtIndex:i];
    NSString *label=[labelDict valueForKey:@"element"];

    NSNumber *offset=[labelDict valueForKey:@"x"];

    float location=[offset floatValue]*multiplier; 
    CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: label textStyle:labelStyle]; 
    newLabel.tickLocation = CPDecimalFromFloat(location); 
    newLabel.offset = x.labelOffset + x.majorTickLength;
    [customTicks addObject:[NSDecimalNumber decimalNumberWithDecimal:CPDecimalFromFloat(location)]];
    [customLabels addObject:newLabel];
    [newLabel release];
}
x.axisLabels =  [NSSet setWithArray:customLabels];
[x setMinorTickLocations:[NSSet setWithArray:customTicks]];
[x setMajorTickLocations:[NSSet setWithArray:customTicks]];
[customTicks release];

1 个答案:

答案 0 :(得分:1)

使用CPAxisLabelingPolicyNone,您还需要提供刻度线位置(minorTickLocationsmajorTickLocations)。

相关问题