0

我正在做一个项目,我想在图中显示用户数据..

我想使用 webview、html、javascript 和 css 文件显示图形。

在 webview 我得到表格而不是图表。

我正在正确获取所有 .js 和 .css 文件的文件路径。

我已经在副本捆绑资源中复制了 .js 和 .css 文件。

这是我的代码

NSURL* path = [[NSBundle mainBundle] URLForResource:@"jquery.min" withExtension:@"js"];
NSLog(@"PATH %@",path);
NSURL* path1 = [[NSBundle mainBundle] URLForResource:@"03" withExtension:@"js"];
NSLog(@"PATH %@",path1);

NSURL* css1path = [[NSBundle mainBundle] URLForResource:@"common" withExtension:@"css"];

NSLog(@"CSSPATH %@",css1path);

NSURL* css2path = [[NSBundle mainBundle] URLForResource:@"03" withExtension:@"css"];
NSLog(@"CSS2PATH %@",css2path);




NSString *str  = @"<html lang=\"en\">";
str=[str stringByAppendingString:@"<head>"];
str=[str stringByAppendingString:@"<meta charset=\"utf-8\">"];
str=[str stringByAppendingString:@"<meta name=\"viewport\" content=\"width=800\">"];
str=[str stringByAppendingString:@"<title>Sleep Hour Graph of myBeats</title>"];
str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css1path];
str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css2path];
str=[str stringByAppendingString:@"</head>"];

str=[str stringByAppendingString:@"<body>"];

str=[str stringByAppendingString:@"<div id=\"wrapper\">"];

str=[str stringByAppendingString:@"<div class=\"chart\">"];

str=[str stringByAppendingString:@"<h2>Weekly Sleep Graph/Hour</h2>"];

str=[str stringByAppendingString:@"<table id=\"data-table\" border=\"1\" cellpadding=\"10\" cellspacing=\"0\" summary=\"Sleep hours from 2013-08-12 to 2013-08-18\">"];
str=[str stringByAppendingString:@"<caption>Sleep in Hours</caption>"];
str=[str stringByAppendingString:@"<thead>"];
str=[str stringByAppendingString:@"<tr>"];
str=[str stringByAppendingString:@"<td>&nbsp;</td>"];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str1];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str2];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str3];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str4];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str5];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str6];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str7];
str=[str stringByAppendingString:@"</tr>"];
str=[str stringByAppendingString:@"</thead>"];
str=[str stringByAppendingString:@"<tbody>"];
str=[str stringByAppendingString:@"<tr>"];
str=[str stringByAppendingString:@"<th scope=\"row\">Sleep in Hours Per Day</th>"];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str11];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str22];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str33];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str44];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str55];
str=[str stringByAppendingFormat:@"<td>%@</td>",str66];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str77];
str=[str stringByAppendingString:@"</tr>"];
str=[str stringByAppendingString:@"</tbody>"];
str=[str stringByAppendingString:@"</table>"];

str=[str stringByAppendingString:@"</div>"];

str=[str stringByAppendingString:@"</div>"];

str=[str stringByAppendingFormat:@"<script type=\"text/javascript\" src=%@\"></script>",path];

str=[str stringByAppendingFormat:@"<script type=\"text/javascript\" src=%@\"></script>",path1];

str=[str stringByAppendingString:@"</body>"];

str=[str stringByAppendingString:@"</html>"];
NSLog(@"HTMLFINAL %@",str);
[webview loadHTMLString:str baseURL:nil];

[webview stringByEvaluatingJavaScriptFromString:str];

我得到的输出:

在此处输入图像描述

所需的输出:

在此处输入图像描述

4

1 回答 1

0

您的hrefsrc属性缺少前导\".

str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css1path];
                                                                 ^
于 2013-09-17T12:47:25.413 回答