I'm trying to get Googles Chart Api to work on a UIWebView but i just can't get it!
I created the UIWebView, set the delegate to self get my hands on any load error (using the didFailLoadWithError
method, no errors btw), fire the load using a html string this way:
@interface GCAViewController ()
@property (weak, nonatomic) IBOutlet UIButton *buttonGo;
@property (weak, nonatomic) IBOutlet UIWebView *webViewChart;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *spinner;
@end
@implementation GCAViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.webViewChart.delegate = self;
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
NSLog(@"%@", error.description);
}
- (IBAction)buttonGoClick:(id)sender {
NSString *str = @"<html>"
"<head>"
"<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>"
"<script type=\"text/javascript\">"
"alert('t1');"
"google.load('visualization', '1.0', {'packages':['corechart']});"
"google.setOnLoadCallback(drawChart);"
"function drawChart() {"
"var data = new google.visualization.DataTable();"
"data.addColumn('string', 'Topping');"
"data.addColumn('number', 'Slices');"
"data.addRows(["
"['Mushrooms', 3],"
"['Onions', 1],"
"['Olives', 1],"
"['Zucchini', 1],"
"['Pepperoni', 2]"
"]);"
"var options = {'title':'How Much Pizza I Ate Last Night',"
"'width':400px,"
"'height':300px};"
"var chart = new google.visualization.PieChart(document.getElementById('chart_div'));"
"chart.draw(data, options);"
"}"
"</script>"
"</head>"
"<body>"
"<div id=\"chart_div\"></div>"
"</body>"
"</html>";
[self.webViewChart loadHTMLString:str baseURL:nil];
}
@end
and nothing happens! No errors, no messages, nothing!
can anyone help?
Extra info: this is a test app designed to do only this...
EDIT 1: after some debug i got a fix that the error is related to the function DrawChart
. If i remove the function declaration the alert('t1')
happens just fine...