Google chart is not working in Webview
I'm using Google chart api to show the graphs. It was working first time but now if i'm working on graphs then it is not showing the graphs. {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[webView setDelegate:self];
NSString *strHtml = [[NSString alloc] initWithString:
开发者_StackOverflow社区 @"<html>"
@"<head>"
@"<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>"
@"<script type=\"text/javascript\">"
@"google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});"
@"google.setOnLoadCallback(drawChart);"
@"function drawChart() {"
@"var data = new google.visualization.DataTable();"
@"data.addColumn('string', 'DAY');"
@"data.addColumn('number', 'RATE');"
@"data.addRows(1);"
@"data.setValue(0, 0, 'M');"
@"data.setValue(0, 1, 20);"
@"var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));"
@"chart.draw(data, {width:320, height:300, title: 'Daily Winning Statistics',"
@"hAxis: {title: 'Year', titleTextStyle: {color: 'red'}},"
@"vAxis:{minValue:0,maxValue:100},"
@"colors:['red']"
@"});"
@"}"
@"</script>"
@"</head>"
@"<body>"
@"<div id=\"chart_div\"></div>"
@"</body>"
@"</html>"];
NSLog(@"string : %@",strHtml);
NSLog(@"Loading start..");
[webView loadHTMLString:strHtml baseURL:nil];
//[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com/"]]];
NSLog(@"Loading finish");
[self.view addSubview:webView];
}
Is there any problem with baseURL ? or any other. Actually when i started code ,it was showing me graphs but now it's not showing. I don't know what's the wrong with this ?
And You can also copy HTML in API Playground where you can show the chart is showing there but not shown in webview.
URL : http://code.google.com/apis/ajax/playground/?type=visualization
I have just used HTML nothing more !
you can copy HTML code from this link : Copy HTML code
Plz help me
Thanks
I think the problem is that you defined only 2 columns
@"data.addColumn('string', 'DAY');"
@"data.addColumn('number', 'RATE');"
and you 're trying to add 3 values for each row
data.setValue(0, 0, 'M');"
"data.setValue(0, 1, 20);"
and you're not respecting the data types that you defined for each column.
精彩评论