首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心图CPTBarPlot中未与X轴刻度对齐的条形图

核心图CPTBarPlot中未与X轴刻度对齐的条形图
EN

Stack Overflow用户
提问于 2011-12-07 16:58:37
回答 1查看 1.4K关注 0票数 2

我在Cocoa上的Core Plot中遇到了CPTBarPlot的问题。也就是说,我无法实现控制条的步幅宽度。X轴刻度通常设置为从1到无穷大的整数,并在其上绘制散点图。

但是,当绘制条形图时,只有第一列从第一个刻度开始(当然,带有适当的偏移)。Second离它的刻度稍远一点,third和所有其他的也是如此,如截图所示:

我还没有找到任何属性来控制这一点,但是我发现了数据源方法

代码语言:javascript
复制
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index

与绘制散点图时的行为不同。也就是说,它只枚举整数3,它是CPTBarPlotBindingBarTips,不枚举任何其他常量,我特别担心缺少CPTBarPlotBindingBarLocations。

如果我从Plot Gallery mac演示项目启动VerticalBarChart,我会检查并看到相同方法以相同的顺序枚举3,4和2个常量。

我使用的是Core Plot 0.9,我相信在这个演示中是一样的。不过..。

如何解决这个问题?

下面是X轴上的标签和刻度的完整代码;

代码语言:javascript
复制
    x.labelRotation = M_PI/4;
    x.labelingPolicy = CPTAxisLabelingPolicyNone;
    x.labelOffset = 0.0;

    CPTMutableTextStyle *labelStyle = [CPTMutableTextStyle textStyle];
    labelStyle.fontSize = 9.0;
    x.labelTextStyle = labelStyle;

//    NSMutableArray *dateArray = [dataSeries objectAtIndex:0];
    NSMutableArray *customTickLocations = [NSMutableArray array];
    NSMutableArray *xAxisLabels = [NSMutableArray array];

    for (int i=0;i<[dataSeries count];i++) {

        [customTickLocations addObject:[NSDecimalNumber numberWithInt:i+1]];
        [xAxisLabels addObject:[dataSeries objectAtIndex:i]];

    }

    //    [customTickLocations addObject:[NSDecimalNumber numberWithInt:[dateArray count]]];

    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/4;
        [customLabels addObject:newLabel];
        [newLabel release];
    }

    [x setMajorTickLocations:[NSSet setWithArray:customTickLocations]];

    x.axisLabels =  [NSSet setWithArray:customLabels];

我必须补充的是,当散点图在相同的绘图空间上绘制并且完全匹配时,使用的是相同的刻度。

EN

回答 1

Stack Overflow用户

发布于 2011-12-08 11:15:50

field参数将是此枚举的成员之一:

代码语言:javascript
复制
typedef enum _CPTBarPlotField {
    CPTBarPlotFieldBarLocation = 2, ///< Bar location on independent coordinate axis.
    CPTBarPlotFieldBarTip      = 3, ///< Bar tip value.
    CPTBarPlotFieldBarBase     = 4  ///< Bar base (used only if barBasesVary is YES).
} CPTBarPlotField;

如果绘图的plotRange属性为nil (默认值),则绘图将向数据源询问每个条形图的位置和提示。如果barBasesVary ==为YES,它还将询问每个条形图的基值。

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

https://stackoverflow.com/questions/8412613

复制
相关文章

相似问题

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