如何在iphone应用程序中的图表值的y轴上显示$ sign

时间:2012-05-15 10:44:31

标签: iphone graph string-formatting

我有图表显示给定值的百分号,但我希望$ i在我的代码中更改为$,但它也隐藏了所有值

     -(void)drawHistogramWithItem:(ECGraphItem *)item index:(int)index color:(UIColor *)color
    {
if (index != 0) 
    _histogramStartX += _histogramSpacing + item.width;
CGRect rect = CGRectMake(_histogramStartX, _xaxisStart.y - _ySpacingScale*item.yValue,item.width, _ySpacingScale*item.yValue);
[color setFill];
[[UIColor blackColor] setStroke];
CGContextAddRect(_context,rect);
CGContextDrawPath(_context, kCGPathFillStroke);
[[UIColor blackColor] set];
NSString *percentage = [NSString stringWithFormat:@"%.1f%%",item.yValue];

[percentage drawAtPoint:CGPointMake(_histogramStartX,_xaxisStart.y - _ySpacingScale*item.yValue - 15) withFont:[UIFont boldSystemFontOfSize:10]];
[self drawWords:item.name AtPoint:CGPointMake(_histogramStartX + item.width/8 ,_xaxisStart.y + 5)  color:[UIColor blackColor]];
    }

1 个答案:

答案 0 :(得分:0)

改变一下:

NSString *percentage = [NSString stringWithFormat:@"%.1f%%",item.yValue];

到那个:

NSString *percentage = [NSString stringWithFormat:@"%.1f$",item.yValue];

它应该工作。希望它有所帮助