开发者

IPhone Development - Chart From Google API

I'm trying to use the Google API to put some graphics in my application but it's not workig. I tested the code for other images on internet and it worked.

Code:

- (void)viewDidLoad {  
    [super viewDidLoad];  
    UIImage *myimage = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://chart.apis.google.com/chart?cht=bvo&chd=t:10,50,60,80,40&chl=Hello|World|hi&chs开发者_如何学JAVA=250x100"]]];  
    UIImageView *test = [[UIImageView alloc] initWithImage:myimage];  
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];  
    [myView addSubview:test];  
    [self.view addSubview:myView];  
}

Thanks, Claudio


Part of your problem is that you have compounded so many statements into one line. If you broke it up it would be easier to tell what is going on.

The issue is the '|' character in the URL string. If you give the chart a plain alphanumeric title it will load. If you replace the '|' with "%7C" it will load.

"http://chart.apis.google.com/chart?cht=bvo&chd=t:10,50,60,80,40&chl=Hello%7CWorld%7Chi&chs=250x100"

is the URL you should use.

See this answer for ways you can check every string you want to use as a URL - it's a good idea to check for all problematic characters or things will fail when you least expect it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜