s7graphview 示例

发布于 2024-08-14 02:55:23 字数 348 浏览 4 评论 0原文

我正在寻找一个适用于 iPhone 的图形库,它允许我将文本设置为 X 轴上的值。快速查看 core-plot 后,它似乎无法做到这一点。我偶然发现了 s7graphview 但似乎无法让它工作。

有没有人确实成功了,并且可以与我分享?或者有一些例子的链接吗? 它认为我的大脑只是因为迟到而关闭了,但我正在尝试;)

最诚挚的问候, 保罗·皮伦

I am looking for an graph library for the iPhone which allowes me to set texts as values on the X-axis. After a quick look at core-plot, it seems its uncapable to do so. I stumbled over s7graphview but can't seem to get it working.

Is there anyone who did got it working, and might be able to share it with me? Or any links to some examples?
It think my brain just shut off cause its late, but I am giving it a try ;)

Best regards,
Paul Peelen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野味少女 2024-08-21 02:55:23

Core Plot 确实支持 X 轴上的自定义刻度标签:
替代文本
(来源:sunsetlakesoftware.com

要生成这些自定义标签,您只需将 X 轴的标签策略设置为 CPAxisLabelingPolicyNone 并提供您自己的标签策略。例如,您可以执行以下操作来复制上面的绘图(在 Core Plot iPhone 测试应用程序中):

x.labelRotation = M_PI/4;
x.labelingPolicy = CPAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations)
{
    CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
    newLabel.tickLocation = [tickLocation decimalValue];
    newLabel.offset = x.labelOffset + x.majorTickLength;
    newLabel.rotation = M_PI/4;
    [customLabels addObject:newLabel];
    [newLabel release];
}

x.axisLabels =  [NSSet setWithArray:customLabels];

无需子类化 CPAxis 来添加这些标签。

Core Plot does indeed support custom tick labels on the X axis:
alt text
(source: sunsetlakesoftware.com)

To produce these custom labels, you just need to set the labeling policy of the X axis to CPAxisLabelingPolicyNone and provide your own. For example, you can do the following to replicate the above drawing (in the Core Plot iPhone test application):

x.labelRotation = M_PI/4;
x.labelingPolicy = CPAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations)
{
    CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
    newLabel.tickLocation = [tickLocation decimalValue];
    newLabel.offset = x.labelOffset + x.majorTickLength;
    newLabel.rotation = M_PI/4;
    [customLabels addObject:newLabel];
    [newLabel release];
}

x.axisLabels =  [NSSet setWithArray:customLabels];

There's no need to subclass CPAxis to add these labels.

墨离汐 2024-08-21 02:55:23

您可以更改标签名称,如

-(NSArray *)newAxisLabelsAtLocations:(NSArray *)locations
{
    NSMutableArray *newLabels = [[NSMutableArray alloc] initWithCapacity:locations.count];
    for ( NSDecimalNumber *tickLocation in locations ) {
        NSString *labelString = [self.labelFormatter stringForObjectValue:tickLocation];
        CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText:[NSString stringWithFormat:@"Day %@",labelString] textStyle:self.labelTextStyle];
        //[newLabel setTextColor:[CPColor whiteColor]];
        newLabel.tickLocation = [tickLocation decimalValue];
        newLabel.rotation = self.labelRotation;
        switch ( self.tickDirection ) {
            case CPSignNone:
                newLabel.offset = self.labelOffset + self.majorTickLength / 2.0f;
                break;
            case CPSignPositive:
            case CPSignNegative:
                newLabel.offset = self.labelOffset + self.majorTickLength;
                break;
        }
        [newLabels addObject:newLabel];
        [newLabel release];
    }
    return newLabels;
}

core-plot 中的 CPAxis.m

希望这有帮助...;)

You can change the label names as

-(NSArray *)newAxisLabelsAtLocations:(NSArray *)locations
{
    NSMutableArray *newLabels = [[NSMutableArray alloc] initWithCapacity:locations.count];
    for ( NSDecimalNumber *tickLocation in locations ) {
        NSString *labelString = [self.labelFormatter stringForObjectValue:tickLocation];
        CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText:[NSString stringWithFormat:@"Day %@",labelString] textStyle:self.labelTextStyle];
        //[newLabel setTextColor:[CPColor whiteColor]];
        newLabel.tickLocation = [tickLocation decimalValue];
        newLabel.rotation = self.labelRotation;
        switch ( self.tickDirection ) {
            case CPSignNone:
                newLabel.offset = self.labelOffset + self.majorTickLength / 2.0f;
                break;
            case CPSignPositive:
            case CPSignNegative:
                newLabel.offset = self.labelOffset + self.majorTickLength;
                break;
        }
        [newLabels addObject:newLabel];
        [newLabel release];
    }
    return newLabels;
}

in the CPAxis.m in core-plot

Hope this helps... ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文