首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在核心图中设置条形宽度的正确方法?

在核心图中设置条形宽度的正确方法?
EN

Stack Overflow用户
提问于 2014-01-14 22:26:49
回答 1查看 1.1K关注 0票数 2

随着更多的数据被添加到我的图表中,我的酒吧高度似乎在缩小和增长。是否有可能修复它,使其每次保持不变(例如10 it高)?

以下是我认为的相关代码:

代码语言:javascript
复制
#define kBarHeight 10

-(void)configurePlots {




    CPTBarPlot *countryPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:19/255.0 green:221/255.0 blue:187/255.0 alpha:1] horizontalBars:YES];

    countryPlot.identifier = @"CountryPlot";

    CPTBarPlot *timeZonePlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:30/255.0 green:33/255.0 blue:36/255.0 alpha:1] horizontalBars:YES];
    timeZonePlot.identifier = @"TimeZonePlot";


    CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
    barLineStyle.lineColor = [CPTColor lightGrayColor];
    barLineStyle.lineWidth = 0.5;

    CPTGraph *countryGraph = self.countryGraph.hostedGraph;
    CPTGraph *timeZoneGraph = self.timeZoneGraph.hostedGraph;

    countryPlot.dataSource = self;
    countryPlot.delegate = self;
    countryPlot.barWidth = CPTDecimalFromDouble(kBarHeight);
    countryPlot.baseValue = CPTDecimalFromString(@"0");
    countryPlot.lineStyle = barLineStyle;
    countryPlot.barOffset = CPTDecimalFromFloat(0.25f);
    countryPlot.labelOffset = -10.0;
    [countryGraph addPlot:countryPlot toPlotSpace:countryGraph.defaultPlotSpace];


    timeZonePlot.dataSource = self;
    timeZonePlot.delegate = self;
    timeZonePlot.baseValue = CPTDecimalFromString(@"0");
    timeZonePlot.barWidth = CPTDecimalFromDouble(kBarHeight);
    timeZonePlot.lineStyle = barLineStyle;
    timeZonePlot.labelOffset = -10.0;
    timeZonePlot.barOffset = CPTDecimalFromFloat(0.25f);

    [timeZoneGraph addPlot:timeZonePlot toPlotSpace:timeZoneGraph.defaultPlotSpace];

}

 //Setting the ranges - possibly the incorrect part?
 CPTXYPlotSpace *countryPlotSpace = (CPTXYPlotSpace *) countryGraph.defaultPlotSpace;
    CSGeoStat *stat = (CSGeoStat *) self.countryData[self.countryData.count-1];
    countryPlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(stat.count * 1.1)];
    countryPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-20.0) length:CPTDecimalFromFloat([self.countryData count]*kBarHeight*1.5)];

    CPTXYPlotSpace *timeZonePlotSpace = (CPTXYPlotSpace *) timeZoneGraph.defaultPlotSpace;
    stat = (CSGeoStat *) self.timeZoneData[self.timeZoneData.count-1];
    timeZonePlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(stat.count * 1.1)];
    timeZonePlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-20.0) length:CPTDecimalFromFloat([self.timeZoneData count]*kBarHeight*1.5)];

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
    NSNumber *num = @0;
    //Bars are horizontal, too! 
    switch (fieldEnum) {
        case CPTBarPlotFieldBarTip:
            if ([plot.identifier isEqual:@"CountryPlot"]) {
                num = [NSNumber numberWithInteger:[self.countryData[index] count]];
            } else {
                num = [NSNumber numberWithInteger:[self.timeZoneData[index] count]];

            }
            break;

        default:
            num = [NSNumber numberWithInteger:(index*(kBarHeight+3)) + kBarHeight/2 ];

            break;
    }
    return num;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-14 22:36:02

试试这个:

代码语言:javascript
复制
countryPlot.barWidthsAreInViewCoordinates = YES;
countryPlot.barWidths = 10.0;

第一行告诉Core绘图使用视图坐标而不是绘图坐标。

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

https://stackoverflow.com/questions/21125346

复制
相关文章

相似问题

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