代码之家  ›  专栏  ›  技术社区  ›  Tirth

如何在图形x轴和y轴间隔点上写入文本?

  •  1
  • Tirth  · 技术社区  · 14 年前

    我使用nsobject类和cgcontext方法开发了图。以下代码以x轴和y轴间隔动态显示,

        CGContextSetRGBStrokeColor(ctx, 2.0, 2.0, 2.0, 1.0);
        CGContextSetLineWidth(ctx, 2.0);
        CGContextMoveToPoint(ctx, 30.0, 200.0);
        CGContextAddLineToPoint(ctx, 30.0, 440.0);
        for(float y = 400.0; y >= 200.0; y-=30)
           {   
               CGContextSetRGBStrokeColor(ctx, 2.0, 2.0, 2.0, 1.0);   
               CGContextMoveToPoint(ctx, 28, y);
               CGContextAddLineToPoint(ctx, 32, y);
               CGContextStrokePath(ctx);
               //CGContextClosePath(ctx);  
            }
    
        CGContextMoveToPoint(ctx, 10, 420.0);       
        CGContextAddLineToPoint(ctx, 320, 420.0);
        //CGContextAddLineToPoint(ctx, 320.0, 420.0);
        //CGContextStrokePath(ctx);
        for(float x = 60.0; x <= 260.0; x+=30)
           {   
               CGContextSetRGBStrokeColor(ctx, 2.0, 2.0, 2.0, 1.0);   
               CGContextMoveToPoint(ctx, x, 418.0);
               CGContextAddLineToPoint(ctx, x, 422.0);
               CGContextStrokePath(ctx);
               CGContextClosePath(ctx);  
            }
    

    我想把动态文本写在x轴和y轴上靠近间隔的地方(比如x轴表示每周的天数,y轴表示每件事的某些内容)? 谢谢。

    2 回复  |  直到 14 年前
        1
  •  5
  •   Steve Harrison    14 年前

    你可能想看看 Core Plot 框架。

        2
  •  1
  •   Khat    14 年前

    上面史蒂夫提供的链接有源代码。在上面写着“来源”的标签下

    http://code.google.com/p/core-plot/source/browse/