首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用核心图时,轴上的数字不显示

使用核心图时,轴上的数字不显示
EN

Stack Overflow用户
提问于 2011-11-02 01:08:30
回答 1查看 1.8K关注 0票数 2

我正在使用Core Plot library为我的iOS应用程序制作图表

然而,我的轴没有显示任何数字或标签:

下面是我的viewDidLoad方法:

代码语言:javascript
运行
复制
- (void)viewDidLoad
{
    [super viewDidLoad];
    //[self generateExponentialDataSamples];
    [self generateGraphDataSamples];

    CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:hostingView];

    // Create graph from theme
    CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
    CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
    [graph applyTheme:theme];
    graph.paddingLeft = 30.0;
    graph.paddingTop = 30.0;
    graph.paddingRight = 30.0;
    graph.paddingBottom = 30.0;              

    hostingView.hostedGraph = graph;

    // Title
    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
    textStyle.color = [CPTColor greenColor];
    textStyle.fontSize = 18.0f;
    textStyle.fontName = @"Helvetica";
    graph.title = @"My Progress";
    graph.titleTextStyle = textStyle;
    graph.titleDisplacement = CGPointMake(0.0f, -20.0f);

    double xAxisStart = 0.0;
    double xAxisLength = MAX_X_VALUE;
    double yAxisStart = 0.0;
    //double yAxisLength = [[samples valueForKeyPath:@"@max.Y_VAL"]doubleValue];
    double yAxisLength = 10;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange  plotRangeWithLocation:CPTDecimalFromDouble(xAxisStart) length:CPTDecimalFromDouble(xAxisLength)];
    plotSpace.yRange = [CPTPlotRange  plotRangeWithLocation:CPTDecimalFromDouble(yAxisStart) length:CPTDecimalFromDouble(yAxisLength)];

    //Axis
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;

    CPTXYAxis *x = axisSet.xAxis;
    x.minorTicksPerInterval = 0; //the number of minor ticks between every major tick
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); // The axis should begin in the origin
    x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
    x.title = @"x-axis";
    x.titleTextStyle = textStyle;

    CPTXYAxis *y = axisSet.yAxis;
    y.minorTicksPerInterval = 0;
    y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
    y.title = @"y-axis";
    y.titleTextStyle = textStyle;

    CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc]init];
    dataSourceLinePlot.dataSource = self;

    // Add line style
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineWidth = 1.0f;
    lineStyle.lineColor = [CPTColor greenColor];
    dataSourceLinePlot.dataLineStyle = lineStyle;

    // create the fill area
    dataSourceLinePlot.areaFill = [CPTFill fillWithColor:[[CPTColor greenColor] colorWithAlphaComponent:0.2f]];
    dataSourceLinePlot.areaBaseValue = CPTDecimalFromString(@"0");

    [graph addPlot:dataSourceLinePlot];
}

有点乱七八糟的,但我真的很感谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-02 10:00:35

设置每个轴的刻度方向:

代码语言:javascript
运行
复制
x.tickDirection = CPTSignPositive;
y.tickDirection = CPTSignPositive;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7970092

复制
相关文章

相似问题

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