我正在嘗試將圖表構建到我的MacOS應用程序中,並決定不使用本機objective-c中可用的有限選項,我最好使用HTML 5並嵌入WebView控件。使用JavaScript在WebView中呈現HTML5圖表
我設法嵌入WebView好吧,通過鏈接到我的應用程序的一部分的index.html文件,使用以下內容。
// Load the HTML content.
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/index.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
我測試了一些簡單的html,所以我知道它連接好了。但是,當嵌入一些更復雜的代碼時,它包含一些CSS和JS,它不會呈現。如果我在Safari瀏覽器窗口中加載index.html
,它會呈現圖表。
有什麼更多我必須做的,以使Javascript執行?
對於額外的細節,圖表使用JQPlot,和索引文件的內容是......
<html>
<head>
<script language="javascript" type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.min.css" />
</head>
<body>
<div id="chartdiv" style="height:200px;width:300px; "></div>
<script>
$.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
</script>
</body>
</html>
更新:
我都進行了詳細的分析,我發現我可以執行標準的JavaScript,但jQuery不起作用。所以,我猜測問題是在html頁面的頂部加載腳本標籤。